packet(7) Miscellaneous Information Manual packet(7) packet - #include #include #include /* the L2 protocols */ packet_socket = socket(AF_PACKET, int socket_type, int protocol); ( OSI). . socket_type SOCK_RAW SOCK_DGRAM . sockaddr_ll. protocol IEEE 802.3 . . htons(ETH_P_ALL) . . protocol . bind(2) sll_protocol . CAP_NET_RAW . SOCK_RAW . sockaddr_ll . . . . SOCK_RAW AF_INET/SOCK_PACKET Linux 2.0 . SOCK_DGRAM . . SOCK_DGRAM sockaddr_ll . . bind(2) struct sockaddr_ll . sll_family ( AF_PACKET) sll_protocol sll_ifindex. connect(2) . MSG_TRUNC recvmsg(2) recv(2) recvfrom(2) . sockaddr_ll . struct sockaddr_ll { unsigned short sll_family; /* Always AF_PACKET */ unsigned short sll_protocol; /* Physical-layer protocol */ int sll_ifindex; /* Interface number */ unsigned short sll_hatype; /* ARP hardware type */ unsigned char sll_pkttype; /* Packet type */ unsigned char sll_halen; /* Size of address */ unsigned char sll_addr[8]; /* Physical-layer address */ }; : sll_protocol . . sll_ifindex ( netdevice(7)) 0 ( ). sll_hatype ARP . sll_pkttype . PACKET_HOST PACKET_BROADCAST PACKET_MULTICAST PACKET_OTHERHOST PACKET_OUTGOING . . sll_addr sll_halen ( IEEE 802.3) . . sll_family sll_addr sll_halen sll_ifindex sll_protocol. 0. sll_hatype sll_pkttype . setsockopt(2) SOL_PACKET. PACKET_ADD_MEMBERSHIP PACKET_DROP_MEMBERSHIP . PACKET_ADD_MEMBERSHIP PACKET_DROP_MEMBERSHIP. packet_mreq : struct packet_mreq { int mr_ifindex; /* interface index */ unsigned short mr_type; /* action */ unsigned short mr_alen; /* address size */ unsigned char mr_address[8]; /* physical-layer address */ }; mr_ifindex . mr_type . PACKET_MR_PROMISC ( " ") PACKET_MR_MULTICAST mr_address mr_alen PACKET_MR_ALLMULTI . ioctls SIOCSIFFLAGS SIOCADDMULTI SIOCDELMULTI . PACKET_AUXDATA ( 2.6.21) recvmsg(2). cmsg(3). : struct tpacket_auxdata { __u32 tp_status; __u32 tp_len; /* packet size */ __u32 tp_snaplen; /* captured size */ __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 ( 3.1) . . setsockopt(2) SOL_PACKET PACKET_FANOUT. 65536 . 16 . . ( ). . . : o PACKET_FANOUT_HASH . . o PACKET_FANOUT_LB round-robin. o PACKET_FANOUT_CPU . o PACKET_FANOUT_ROLLOVER . o PACKET_FANOUT_RND . o PACKET_FANOUT_QM ( 3.14) queue_mapping skb . . IP . PACKET_FANOUT_FLAG_DEFRAG . 16 . PACKET_FANOUT_FLAG_ROLLOVER : . PACKET_LOSS ( PACKET_TX_RING) tp_status TP_STATUS_WRONG_FORMAT . . tp_status TP_STATUS_SEND_REQUEST send(2). PACKET_LOSS tp_status TP_STATUS_AVAILABLE . PACKET_RESERVE ( PACKET_RX_RING) . . PACKET_RX_RING . ( tp_snaplen) . tpacket_auxdata. . tp_net . SOCK_DGRAM tp_mac . SOCK_RAW . tp_status. tp_status TP_STATUS_KERNEL. . tp_status TP_STATUS_USER . tp_status TP_STATUS_KERNEL. . Documentation/networking/packet_mmap.rst . PACKET_STATISTICS struct tpacket_stats { unsigned int tp_packets; /* Total packet count */ unsigned int tp_drops; /* Dropped packet count */ }; . TPACKET_V3. PACKET_TIMESTAMP ( PACKET_RX_RING 2.6.36) . . . Documentation/networking/timestamping.rst . PACKET_TX_RING ( 2.6.31) . PACKET_RX_RING . tp_status TP_STATUS_AVAILABLE tp_status TP_STATUS_SEND_REQUEST. send(2) . buf len . sendto(2) sendmsg(2) . tp_status TP_STATUS_AVAILABLE. PACKET_LOSS. PACKET_VERSION ( PACKET_RX_RING 2.6.27) PACKET_RX_RING TPACKET_V1. . PACKET_QDISC_BYPASS ( 3.14) qdisc ( ) . -- pktgen-- 1. qdisc . Ioctls SIOCGSTAMP . struct timeval. ioctls netdevice(7) socket(7) . . . EADDRNOTAVAIL . EFAULT . EINVAL . EMSGSIZE MTU . ENETDOWN . ENOBUFS . ENODEV . ENOENT . ENOTCONN . ENXIO . EPERM . . AF_PACKET 2.2. SOCK_PACKET. AF_PACKET pcap(3) AF_PACKET. SOCK_DGRAM IEEE 802.2 LLC IEEE 802.3. ETH_P_802_3 802.3 LLC . 802.3 DSAP/SSAP ETH_P_802_2 LLC . ETH_P_802_3 ETH_P_802_2 . Ethernet DIX . . 2.0 : socket(AF_INET, SOCK_PACKET, protocol) . SOCK_PACKET struct sockaddr_pkt . struct sockaddr_pkt { unsigned short spkt_family; unsigned char spkt_device[14]; unsigned short spkt_protocol; }; spkt_family spkt_protocol IEEE 802.3 spkt_device eth0. . LLC IEEE 802.2/803.3 LLC . MSG_TRUNC MSG_TRUNC recvmsg(2) . SOCK_DGRAM. spkt_device spkt_device sockaddr_pkt 14 IFNAMSIZ 16 . 14 spkt_device. ('\0')). Predictable Network Interface Names . SOCK_PACKET. Predictable Network Interface Names 13 ip(8). . socket(2), pcap(3), capabilities(7), ip(7), raw(7), socket(7), ip(8), RFC 894 IP Ethernet . RFC 1700 IP IEEE 802.3. . . Documentation/networking/filter.rst . tools/testing/selftests/net/psock_tpacket.c PACKET_RX_RING PACKET_TX_RING. 3 . . : . 6.18 8 2026 packet(7)