-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiping.h
163 lines (151 loc) · 7.11 KB
/
iping.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// iping.h: a header file for iping.c
#ifndef IPING_H // include guard to prevent multiple inclusion
#define IPING_H
// Standard Library Headers
#include <stdint.h>
#include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <unistd.h>
// #include <sys/socket.h>
// #include <netinet/in.h>
// #include <arpa/inet.h>
// Constants
#ifndef IPV4
#define IPV4 1
#endif
#ifndef IPV6
#define IPV6 2
#endif
#ifndef TCP
#define TCP 1
#endif
#ifndef UDP
#define UDP 2
#endif
// Type Defs
typedef __uint128_t uint128_t;
//Some Useful Structures for Managing Traffic Generation
//////////////////////////////////////////////////////////////////////////
/// IPV4 Header Format
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |Version| IHL |Type of Service| Total Length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Identification |Flags| Fragment Offset |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Time to Live | Protocol | Header Checksum |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Source Address |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Destination Address |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Options | Padding |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// For more information: Resources/RFC791.txt
/////////////////////////////////////////////////////////////////////////
typedef struct ipv4_hdr {
uint8_t ihl:4,version:4;
uint8_t tos;
uint16_t total_length;
uint16_t id;
uint16_t frag_off:13,flags:3;
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t source_addr;
uint32_t dest_addr;
//Note that options and padding are not included in the ipv4_hdr struct
}ipv4_hdr;
//////////////////////////////////////////////////////////////////////////
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |Version| Traffic Class | Flow Label |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Payload Length | Next Header | Hop Limit |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// + +
// | |
// + Source Address +
// | |
// + +
// | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// + +
// | |
// + Destination Address +
// | |
// + +
// | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//////////////////////////////////////////////////////////////////////////
typedef struct ipv6_hdr {
uint32_t flow_label:20,traffic_class:8,version:4;
uint16_t payload_length;
uint8_t next_header;
uint8_t hop_limit;
uint128_t source_addr;
uint128_t dest_addr;
//Note that the ipv6_hdr struct does not include extension headers
};
//////////////////////////////////////////////////////////////////////////
//
// User Data Protocol Header Format
// 0 7 8 15 16 23 24 31
// +--------+--------+--------+--------+
// | Source | Destination |
// | Port | Port |
// +--------+--------+--------+--------+
// | | |
// | Length | Checksum |
// +--------+--------+--------+--------+
//
// For more information: Resources/RFC768.txt
//////////////////////////////////////////////////////////////////////////
struct udp_hdr {
uint16_t source_port; // Destination Port. Port of the sending process, may be assumed. If not used, 0.
uint16_t dest_port; // Destination Port. Required.
uint16_t length; // Length of this header + data
uint16_t checksum; // Checksum. 16 bit ones complement of the one's complement sum of a pseudo header + this header + data.
};
//////////////////////////////////////////////////////////////////////////
// Transmission Control Protocol Header Format
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Source Port | Destination Port |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Acknowledgment Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Data | |C|E|U|A|P|R|S|F| |
// | Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window |
// | | |R|E|G|K|H|T|N|N| |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Checksum | Urgent Pointer |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | [Options] |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | :
// : Data :
// : |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// For more information: Resources/RFC9293.txt
//////////////////////////////////////////////////////////////////////////
struct tcp_hdr {
uint16_t source_port; //Source Port
uint16_t dest_port;
uint32_t seq_number;
uint32_t ack_number;
uint8_t rsrvd:4, d_off:4;
uint8_t flags;
uint16_t window;
uint16_t checksum;
uint16_t urgentpointer;
//Note that there may be aditional options for TCP Header.
//The tcp_hdr struct only contains base.
};
#endif /* IPING_H */