1 #pragma once
2 
3 #include <stdint.h>
4 #include <sys/types.h>
5 
6 #define ETH_ALEN 6
7 #define ETH_HLEN 14
8 #define ETH_ZLEN 60
9 #define ETH_DATA_LEN 1500
10 #define ETH_FRAME_LEN 1514
11 #define ETH_FCS_LEN 4
12 
13 #define ETH_P_LOOP 0x0060
14 #define ETH_P_PUP 0x0200
15 #define ETH_P_PUPAT 0x0201
16 #define ETH_P_IP 0x0800
17 #define ETH_P_X25 0x0805
18 #define ETH_P_ARP 0x0806
19 #define ETH_P_BPQ 0x08FF
20 #define ETH_P_IEEEPUP 0x0a00
21 #define ETH_P_IEEEPUPAT 0x0a01
22 #define ETH_P_BATMAN 0x4305
23 #define ETH_P_DEC 0x6000
24 #define ETH_P_DNA_DL 0x6001
25 #define ETH_P_DNA_RC 0x6002
26 #define ETH_P_DNA_RT 0x6003
27 #define ETH_P_LAT 0x6004
28 #define ETH_P_DIAG 0x6005
29 #define ETH_P_CUST 0x6006
30 #define ETH_P_SCA 0x6007
31 #define ETH_P_TEB 0x6558
32 #define ETH_P_RARP 0x8035
33 #define ETH_P_ATALK 0x809B
34 #define ETH_P_AARP 0x80F3
35 #define ETH_P_8021Q 0x8100
36 #define ETH_P_IPX 0x8137
37 #define ETH_P_IPV6 0x86DD
38 #define ETH_P_PAUSE 0x8808
39 #define ETH_P_SLOW 0x8809
40 #define ETH_P_WCCP 0x883E
41 #define ETH_P_MPLS_UC 0x8847
42 #define ETH_P_MPLS_MC 0x8848
43 #define ETH_P_ATMMPOA 0x884c
44 #define ETH_P_PPP_DISC 0x8863
45 #define ETH_P_PPP_SES 0x8864
46 #define ETH_P_LINK_CTL 0x886c
47 #define ETH_P_ATMFATE 0x8884
48 #define ETH_P_PAE 0x888E
49 #define ETH_P_AOE 0x88A2
50 #define ETH_P_8021AD 0x88A8
51 #define ETH_P_802_EX1 0x88B5
52 #define ETH_P_TIPC 0x88CA
53 #define ETH_P_8021AH 0x88E7
54 #define ETH_P_MVRP 0x88F5
55 #define ETH_P_1588 0x88F7
56 #define ETH_P_PRP 0x88FB
57 #define ETH_P_FCOE 0x8906
58 #define ETH_P_TDLS 0x890D
59 #define ETH_P_FIP 0x8914
60 #define ETH_P_80221 0x8917
61 #define ETH_P_LOOPBACK 0x9000
62 #define ETH_P_QINQ1 0x9100
63 #define ETH_P_QINQ2 0x9200
64 #define ETH_P_QINQ3 0x9300
65 #define ETH_P_EDSA 0xDADA
66 #define ETH_P_AF_IUCV 0xFBFB
67 
68 #define ETH_P_802_3_MIN 0x0600
69 
70 #define ETH_P_802_3 0x0001
71 #define ETH_P_AX25 0x0002
72 #define ETH_P_ALL 0x0003
73 #define ETH_P_802_2 0x0004
74 #define ETH_P_SNAP 0x0005
75 #define ETH_P_DDCMP 0x0006
76 #define ETH_P_WAN_PPP 0x0007
77 #define ETH_P_PPP_MP 0x0008
78 #define ETH_P_LOCALTALK 0x0009
79 #define ETH_P_CAN 0x000C
80 #define ETH_P_CANFD 0x000D
81 #define ETH_P_PPPTALK 0x0010
82 #define ETH_P_TR_802_2 0x0011
83 #define ETH_P_MOBITEX 0x0015
84 #define ETH_P_CONTROL 0x0016
85 #define ETH_P_IRDA 0x0017
86 #define ETH_P_ECONET 0x0018
87 #define ETH_P_HDLC 0x0019
88 #define ETH_P_ARCNET 0x001A
89 #define ETH_P_DSA 0x001B
90 #define ETH_P_TRAILER 0x001C
91 #define ETH_P_PHONET 0x00F5
92 #define ETH_P_IEEE802154 0x00F6
93 #define ETH_P_CAIF 0x00F7
94 
95 struct ethhdr {
96     uint8_t h_dest[ETH_ALEN];
97     uint8_t h_source[ETH_ALEN];
98     uint16_t h_proto;
99 };
100 
101 #include <net/ethernet.h>
102 #include <net/if_arp.h>
103 
104 struct ether_arp {
105     struct arphdr ea_hdr;
106     uint8_t arp_sha[ETH_ALEN];
107     uint8_t arp_spa[4];
108     uint8_t arp_tha[ETH_ALEN];
109     uint8_t arp_tpa[4];
110 };
111 #define arp_hrd ea_hdr.ar_hrd
112 #define arp_pro ea_hdr.ar_pro
113 #define arp_hln ea_hdr.ar_hln
114 #define arp_pln ea_hdr.ar_pln
115 #define arp_op ea_hdr.ar_op
116 
117 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr)      \
118     do {                                            \
119         (enaddr)[0] = 0x01;                         \
120         (enaddr)[1] = 0x00;                         \
121         (enaddr)[2] = 0x5e;                         \
122         (enaddr)[3] = ((uint8_t*)ipaddr)[1] & 0x7f; \
123         (enaddr)[4] = ((uint8_t*)ipaddr)[2];        \
124         (enaddr)[5] = ((uint8_t*)ipaddr)[3];        \
125     } while (0)
126