PACKET_AUXDATA (since Linux 2.6.21)
If this binary option is enabled, the packet socket passes a metadata structure along with each packet in the recvmsg(2) control field. The structure can be read with cmsg(3). It is defined as
structtpacket_auxdata {
__u32 tp_status;
__u32 tp_len; /* packet length */
__u32 tp_snaplen; /* captured length */
__u16 tp_mac;
__u16 tp_net;
__u16 tp_vlan_tci;
__u16 tp_vlan_tpid; /* Since Linux 3.14; earlier, these
were unused padding bytes */
};
PACKET_FANOUT (since Linux 3.1)
PACKET_RESERVE (with PACKET_RX_RING)
PACKET_RX_RING
PACKET_STATISTICS
PACKET_TIMESTAMP (with PACKET_RX_RING; since Linux 2.6.36)
PACKET_TX_RING (since Linux 2.6.31)
PACKET_VERSION (with PACKET_RX_RING; since Linux 2.6.27)
The SOCK_DGRAM packet sockets make no attempt to create or parse the IEEE 802.2 LLC header for a IEEE 802.3 frame.
SOCK_DGRAM 数据包套接字不会尝试为 IEEE 802.3 帧创建或解析 IEEE 802.2 LLC header。
When ETH_P_802_3 is specified as protocol for sending the kernel creates the 802.3 frame and fills out the length field; the user has to supply the LLC header to get a fully conforming packet.
当 ETH_P_802_3 被指定为发送协议时,内核创建 802.3 帧并填写长度字段;用户必须自行提供 LLC header 才能获得完全符合要求的数据包。
Incoming 802.3 packets are not multiplexed on the DSAP/SSAP protocol fields; instead they are supplied to the user as protocol ETH_P_802_2 with the LLC header prefixed.
传入的 802.3 数据包不会在 DSAP/SSAP 协议字段上复用;相反,它们作为带有 LLC 标头前缀的协议 ETH_P_802_2 提供给用户。
It is thus not possible to bind to ETH_P_802_3; bind to ETH_P_802_2 instead and do the protocol multiplex yourself.
因此无法绑定到 ETH_P_802_3;而是绑定到 ETH_P_802_2 并自己进行协议复用。
The default for sending is the standard Ethernet DIX encapsulation with the protocol filled in.
发送的默认值是标准的以太网 DIX 封装,并填充了协议。
Packet sockets are not subject to the input or output firewall
chains.
Compatibility
In Linux 2.0, the only way to get a packet socket was with the
call:
socket(AF_INET, SOCK_PACKET, protocol)
This is still supported, but deprecated and strongly discouraged.
The main difference between the two methods is that SOCK_PACKET
uses the old struct sockaddr_pkt to specify an interface, which
doesn't provide physical-layer independence.
spkt_family contains the device type, spkt_protocol is the IEEE
802.3 protocol type as defined in <sys/if_ether.h> and
spkt_device is the device name as a null-terminated string, for
example, eth0.
This structure is obsolete and should not be used in new code.
BUGS
The IEEE 802.2/803.3 LLC handling could be considered as a bug.
Socket filters are not documented.
The MSG_TRUNC recvmsg(2) extension is an ugly hack and should be
replaced by a control message. There is currently no way to get
the original destination address of packets via SOCK_DGRAM.