-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw.h
128 lines (115 loc) · 2.19 KB
/
raw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#define ETH_LEN 1518
#define ETHER_TYPE 0x0800
#define DEFAULT_IF "eth0"
struct eth_hdr {
uint8_t dst_addr[6];
uint8_t src_addr[6];
uint16_t eth_type;
};
struct ip_hdr {
uint8_t ver; /* version, header length */
uint8_t tos; /* type of service */
int16_t len; /* total length */
uint16_t id; /* identification */
int16_t off; /* fragment offset field */
uint8_t ttl; /* time to live */
uint8_t proto; /* protocol */
uint16_t sum; /* checksum */
uint8_t src[4]; /* source address */
uint8_t dst[4]; /* destination address */
};
struct icmp_hdr {
uint8_t type;
uint8_t code;
uint16_t checksum;
union {
struct {
uint16_t id;
uint16_t sequence;
} echo;
uint32_t gateway;
struct {
uint16_t __unused;
uint16_t mtu;
} frag;
uint8_t reserved[4];
} un;
};
struct bepis_hdr {
uint32_t target_ip;
};
struct bepis_packet {
struct ip_hdr iphdr;
struct icmp_hdr icmphdr;
struct bepis_hdr bepishdr;
uint8_t raw_data[ETH_LEN - sizeof(struct eth_hdr) - sizeof(struct ip_hdr) - sizeof(struct icmp_hdr) - sizeof(struct bepis_hdr)];
};
struct icmp_packet {
struct ip_hdr iphdr;
struct icmp_hdr icmphdr;
};
struct tcp_hdr {
uint16_t source;
uint16_t dest;
uint32_t seq;
uint32_t ack_seq;
#if defined(__LITTLE_ENDIAN_BITFIELD)
uint16_t res1:4,
doff:4,
fin:1,
syn:1,
rst:1,
psh:1,
ack:1,
urg:1,
ece:1,
cwr:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
uint16_t doff:4,
res1:4,
cwr:1,
ece:1,
urg:1,
ack:1,
psh:1,
rst:1,
syn:1,
fin:1;
#else
#error "Adjust your <asm/byteorder.h> defines"
#endif
uint16_t window;
uint16_t check;
uint16_t urg_ptr;
};
struct tcp_packet {
struct ip_hdr iphdr;
struct tcp_hdr tcphdr;
};
struct udp_hdr {
uint16_t src_port;
uint16_t dst_port;
uint16_t udp_len;
uint16_t udp_chksum;
};
struct udp_packet {
struct ip_hdr iphdr;
struct udp_hdr udphdr;
};
union packet_u {
struct ip_hdr ip;
struct icmp_packet icmp;
struct udp_packet udp;
struct tcp_packet tcp;
struct bepis_packet bepis;
};
#pragma pack(push, 1)
struct eth_frame_s {
struct eth_hdr ethernet;
union packet_u payload;
};
#pragma pack(pop)
union eth_buffer {
struct eth_frame_s cooked_data;
uint8_t raw_data[ETH_LEN];
};