10 #define ETH_TYPE_IP 0x0800
11 #define ETH_TYPE_ARP 0x0806
12 #define ETH_TYPE_VLAN 0x8100
14 #define ETH_HEADER_LEN 14
15 #define ETH_PAYLOAD_MIN 46
16 #define ETH_TOTAL_MIN (ETH_HEADER_LEN + ETH_PAYLOAD_MIN)
18 uint8_t eth_dst[ETH_ADDR_LEN];
19 uint8_t eth_src[ETH_ADDR_LEN];
22 BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
24 #define LLC_DSAP_SNAP 0xaa
25 #define LLC_SSAP_SNAP 0xaa
26 #define LLC_CNTL_SNAP 3
28 #define LLC_HEADER_LEN 3
34 BUILD_ASSERT_DECL(LLC_HEADER_LEN == sizeof(struct llc_header));
36 #define SNAP_ORG_ETHERNET "\0\0" /* The compiler adds a null byte, so
37 sizeof(SNAP_ORG_ETHERNET) == 3. */
38 #define SNAP_HEADER_LEN 5
42 } __attribute__((packed));
43 BUILD_ASSERT_DECL(SNAP_HEADER_LEN == sizeof(struct snap_header));
45 #define LLC_SNAP_HEADER_LEN (LLC_HEADER_LEN + SNAP_HEADER_LEN)
46 struct llc_snap_header {
47 struct llc_header llc;
48 struct snap_header snap;
50 BUILD_ASSERT_DECL(LLC_SNAP_HEADER_LEN == sizeof(struct llc_snap_header));
52 #define VLAN_VID 0x0fff
54 #define VLAN_HEADER_LEN 4
56 uint16_t vlan_tci; /* Lowest 12 bits are VLAN ID. */
57 uint16_t vlan_next_type;
59 BUILD_ASSERT_DECL(VLAN_HEADER_LEN == sizeof(struct vlan_header));
61 #define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4)
62 #define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15)
65 #define IP_TYPE_UDP 17
67 #define IP_HEADER_LEN 20
80 BUILD_ASSERT_DECL(IP_HEADER_LEN == sizeof(struct ip_header));
82 #define UDP_HEADER_LEN 8
89 BUILD_ASSERT_DECL(UDP_HEADER_LEN == sizeof(struct udp_header));
98 #define TCP_FLAGS(tcp_ctl) (htons(tcp_ctl) & 0x003f)
99 #define TCP_OFFSET(tcp_ctl) (htons(tcp_ctl) >> 12)
101 #define TCP_HEADER_LEN 20
112 BUILD_ASSERT_DECL(TCP_HEADER_LEN == sizeof(struct tcp_header));
114 #define ARP_HRD_ETHERNET 1
115 #define ARP_PRO_IP 0x0800
116 #define ARP_OP_REQUEST 1
117 #define ARP_OP_REPLY 2
119 #define ARP_ETH_HEADER_LEN 28
120 struct arp_eth_header {
121 /* Generic members. */
122 uint16_t ar_hrd; /* Hardware type. */
123 uint16_t ar_pro; /* Protocol type. */
124 uint8_t ar_hln; /* Hardware address length. */
125 uint8_t ar_pln; /* Protocol address length. */
126 uint16_t ar_op; /* Opcode. */
128 /* Ethernet+IPv4 specific members. */
129 uint8_t ar_sha[ETH_ADDR_LEN]; /* Sender hardware address. */
130 uint32_t ar_spa; /* Sender protocol address. */
131 uint8_t ar_tha[ETH_ADDR_LEN]; /* Target hardware address. */
132 uint32_t ar_tpa; /* Target protocol address. */
133 } __attribute__((packed));
134 BUILD_ASSERT_DECL(ARP_ETH_HEADER_LEN == sizeof(struct arp_eth_header));
136 #endif /* packets.h */