mdlayher / raw

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.
MIT License
425 stars 71 forks source link

use unix.Write to send packets to raw socket #65

Open pyther opened 4 years ago

pyther commented 4 years ago

Specifying a socketaddr is unnecessary when writing packets to a raw socket. According to packet(7) the supplied buffer should contain a physical-layer header. The sockaddr_ll is used for SOCK_DGRAM.

SOCK_RAW packets are passed to and from the device driver without any changes in the packet data. When receiving a packet, the address is still parsed and passed in a standard sockaddr_ll address structure. When transmitting a packet, the user-supplied buffer should contain the physical-layer header. That packet is then queued unmodified to the network driver of the interface defined by the destination address.

SOCK_DGRAM operates on a slightly higher level. The physical header is removed before the packet is passed to the user. Packets sent through a SOCK_DGRAM packet socket get a suitable physical-layer header based on the information in the sockaddr_ll destination address before they are queued.

http://man7.org/linux/man-pages/man7/packet.7.html