1 | typedef struct { |
---|
2 | unsigned char version; |
---|
3 | unsigned char typeOfService; |
---|
4 | unsigned short length; |
---|
5 | unsigned short identification; |
---|
6 | unsigned short frag_offset; |
---|
7 | unsigned char ttl; |
---|
8 | unsigned char protocol; |
---|
9 | unsigned short checksum; |
---|
10 | unsigned int src_addr_ip; |
---|
11 | unsigned int dest_addr_ip; |
---|
12 | } __attribute__((packed)) ipv4_header; |
---|
13 | |
---|
14 | typedef struct { |
---|
15 | unsigned short hardware_type; |
---|
16 | unsigned short protocol_type; |
---|
17 | unsigned char hard_addr_len; |
---|
18 | unsigned char prot_addr_len; |
---|
19 | unsigned short opcode; |
---|
20 | // unsigned char src_addr_mac[6]; |
---|
21 | unsigned int src_addr_mac_hi; |
---|
22 | unsigned short src_addr_mac_lo; |
---|
23 | unsigned int src_addr_ip; |
---|
24 | // unsigned char dest_addr_mac[6]; |
---|
25 | unsigned int dest_addr_mac_hi; |
---|
26 | unsigned short dest_addr_mac_lo; |
---|
27 | unsigned int dest_addr_ip; |
---|
28 | } __attribute__((packed)) arp_header; |
---|
29 | |
---|
30 | typedef struct { |
---|
31 | u16 sport; // Source port |
---|
32 | u16 dport; // Destination port |
---|
33 | u16 len; // Datagram length |
---|
34 | u16 crc; // Checksum |
---|
35 | } __attribute__((packed)) udp_header; |
---|
36 | |
---|
37 | typedef struct { |
---|
38 | unsigned char dest_addr_mac[6]; |
---|
39 | unsigned char src_addr_mac[6]; |
---|
40 | unsigned short ethertype; |
---|
41 | } __attribute__((packed)) ethernet_header; |
---|
42 | |
---|
43 | #define ETHERTYPE_ARP 0x0806 |
---|
44 | #define ETHERTYPE_IP 0x0800 |
---|
45 | #define IP_HDR_PROTO_UDP 17 |
---|