meh / rust-tun

TUN device creation and handling.
340 stars 133 forks source link

Where is the tun tap frame? #58

Open franklee26 opened 1 year ago

franklee26 commented 1 year ago

Following #19, I'm seeing that all of the data read by my tun device starts with the four bytes [0x00 0x00 0x00 0x02]. I later see my payload in the byte stream but I'm wondering where the actual tun tap frame is?

From the source (https://www.kernel.org/doc/Documentation/networking/tuntap.txt) it states:

  If flag IFF_NO_PI is not set each frame format is: 
     Flags [2 bytes]
     Proto [2 bytes]
     Raw protocol(IP, IPv6, etc) frame.

I am expecting an 0x0800 or 0x86dd (ipv4 / ipv6) respectfully (see https://en.wikipedia.org/wiki/EtherType) but I don't see any of this in any of my traces.

M0dEx commented 1 year ago

MacOS unfortunately uses different values in the protocol field of the 4-byte header.

libc::AF_INET and libc::AF_INET6 respectively.