Tun / tap tries to look like a regular ethernet controller, but the crane itself is connected in the same way as any other file descriptor.
Since it claims to be the ethernet controller, you must know in advance how big the Ethernet frame itself was, this happens either using the software bridge to which the crane device is connected, or from the "length" field to the original ethernet frame.
This, of course, can only be the maximum MTU size of the crane device, which is usually 1500 bytes by default.
So, before you do read () in the file descriptor for the tap device, you need to find out how big the ethernet frame is.
source share