meh / rust-tun

TUN device creation and handling.
343 stars 136 forks source link

4 bytes header on macos #19

Open ihciah opened 4 years ago

ihciah commented 4 years ago

On linux, packet_information default value is false, which means IFF_NO_PI will be used. But on macos, the 4-byte ethernet family header will be passed when read. I think the behavior should be consistent on different platforms. Should the behavior on macos changed? Maybe packet_information can be applied for macos too to control whether remove the header?

meh commented 4 years ago

If that's how it works, yes, I do not have any macOS systems so cannot develop it myself.

tubzby commented 3 years ago

@ihciah I have the same problem on macos, I have been using a Golang implementation without this problem: https://github.com/songgao/water

tubzby commented 3 years ago

I just figured it out, the bytes are [0, 0, 0, 2], 2 stands for AF_INET/ AF_INET6. The header need also to be sent while writing to the socket, a userspace copy is required.

I checked out broingtun: https://github.com/cloudflare/boringtun, it use sengmsg with vectors so that it will reduce data copy.