sockaddr_ll ---设备无关的物理层地址结构
sockaddr_ll: 表示设备无关的物理层地址结构
定义:
- struct sockaddr_ll {
- unsigned short sll_family;
- __be16 sll_protocol;
- int sll_ifindex;
- unsigned short sll_hatype;
- unsigned char sll_pkttype;
- unsigned char sll_halen;
- unsigned char sll_addr[8];
- };
sll_family: 和sockaddr_in中的sa_family一样,地址族的意思。
sll_protocol: 表示上层的协议类型,有如下选择:
- 源文件为<linux/if_ether.h>
-
-
-
-
- #define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */
- #define ETH_P_PUP 0x0200 /* Xerox PUP packet */
- #define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */
- #define ETH_P_IP 0x0800 /* Internet Protocol packet */
- #define ETH_P_X25 0x0805 /* CCITT X.25 */
- #define ETH_P_ARP 0x0806 /* Address Resolution packet */
- #define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet*/
- #define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */
- #define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */
- #define ETH_P_DEC 0x6000 /* DEC Assigned proto */
- #define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */
- #define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */
- #define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */
- #define ETH_P_LAT 0x6004 /* DEC LAT */
- #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
- #define ETH_P_CUST 0x6006 /* DEC Customer use */
- #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
- #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
- #define ETH_P_ATALK 0x809B /* Appletalk DDP */
- #define ETH_P_AARP 0x80F3 /* Appletalk AARP */
- #define ETH_P_IPX 0x8137 /* IPX over DIX */
- #define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
- #define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
- #define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
- #define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */
- #define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport
- * over Ethernet
- */
一般是IP的话选ETH_P_IP。
sll_ifindex: 表示接口类型,源文件<linux/netdevice.h>,有如下选择:
-
- enum {
- IF_PORT_UNKNOWN = 0,
- IF_PORT_10BASE2,
- IF_PORT_10BASET,
- IF_PORT_AUI,
- IF_PORT_100BASET,
- IF_PORT_100BASETX,
- IF_PORT_100BASEFX
- };
sll_hatype:
ARP 硬件地址类型。可以选择,源文件为<net/if_arp.h>
-
- #define ARPHRD_NETROM 0 /* From KA9Q: NET/ROM pseudo. */
- #define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */
- #define ARPHRD_EETHER 2 /* Experimental Ethernet. */
- #define ARPHRD_AX25 3 /* AX.25 Level 2. */
- #define ARPHRD_PRONET 4 /* PROnet token ring. */
- #define ARPHRD_CHAOS 5 /* Chaosnet. */
- #define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB. */
- #define ARPHRD_ARCNET 7 /* ARCnet. */
- #define ARPHRD_APPLETLK 8 /* APPLEtalk. */
- #define ARPHRD_DLCI 15 /* Frame Relay DLCI. */
- #define ARPHRD_ATM 19 /* ATM. */
- #define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id). */
sll_pkttype:包含分组类型
有效的分组类型:
目标地址是本地主机的分组用的 PACKET_HOST,
物理层广播分组用的 PACKET_BROADCAST ,
发送到一个物理层多路广播地址的分组用的 PACKET_MULTICAST,
在混杂(promiscuous)模式下的设备驱动器发向其他主机的分组用的PACKET_OTHERHOST,
本源于本地主机的分组被环回到分组套接口用的 PACKET_OUTGOING。
这些类型只对接收到的分组有意义。
sll_addr 和 sll_halen: 包括物理层(例如 IEEE 802.3)地址和地址长度,精确的解释依赖于设备。
sll_halen 为MAC地址长度(6 bytes)
源文件<linux/if_ether.h>
- #define ETH_ALEN 6 /* Octets in one ethernet addr */
- #define ETH_HLEN 14 /* Total octets in header. */
- #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
- #define ETH_DATA_LEN 1500 /* Max. octets in payload */
- #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
sll_addr[8] 为目的MAC地址(按sockaddr_in.sin_addr为目的IP地址推测)