forked from appneta/tcpreplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defines.h.in
357 lines (291 loc) · 9.44 KB
/
defines.h.in
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#ifndef __DEFINES_H__
#define __DEFINES_H__
#include "config.h"
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef WIN32
#include "msvc_inttypes.h"
#include "msvc_stdint.h"
#else
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#endif /* WIN32 */
#ifdef HAVE_SYS_SOCKET
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_IN_SYSTM_H
#include <netinet/in_systm.h>
#endif
#include "tcpr.h"
#ifdef HAVE_BPF
#include <net/bpf.h>
#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
#endif
#if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
#include "@INCLUDE_PCAP_BPF_HEADER@"
#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
#endif
#include "@LPCAPINC@"
/* include our own strlcat/strlcpy? */
#ifndef HAVE_STRLCPY
#include "lib/strlcpy.h"
#endif
/*
* net/bpf.h doesn't include DLT types, but pcap-bpf.h does.
* Unfortunately, pcap-bpf.h also includes things in net/bpf.h
* while also missing some key things (wow, that sucks)
* The result is that I stole the DLT types from pcap-bpf.h and
* put them in here.
*/
#include "common/dlt_names.h"
#ifdef HAVE_BOOL_H
#include <bool.h>
#endif
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
/* should packet counters be 32 or 64 bit? --enable-64bit */
#ifdef ENABLE_64BITS
#define COUNTER unsigned long long
#define COUNTER_SPEC "%llu"
#else
#define COUNTER unsigned long
#define COUNTER_SPEC "%lu"
#endif
#define COUNTER_OVERFLOW_RISK (((COUNTER)~0) >> 20)
#include "common/list.h"
#include "common/cidr.h"
typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
typedef struct tcpr_ipv6_hdr ipv6_hdr_t;
typedef struct tcpr_tcp_hdr tcp_hdr_t;
typedef struct tcpr_udp_hdr udp_hdr_t;
typedef struct tcpr_icmpv4_hdr icmpv4_hdr_t;
typedef struct tcpr_icmpv6_hdr icmpv6_hdr_t;
typedef struct tcpr_ethernet_hdr eth_hdr_t;
typedef struct tcpr_802_1q_hdr vlan_hdr_t;
typedef struct sll_header sll_hdr_t;
typedef struct tcpr_arp_hdr arp_hdr_t;
typedef struct tcpr_dnsv4_hdr dnsv4_hdr_t;
/* our custom typdefs/structs */
typedef u_char tcpr_macaddr_t[TCPR_ETH_H];
typedef struct tcpr_bpf_s {
char *filter;
int optimize;
struct bpf_program program;
} tcpr_bpf_t;
typedef struct tcpr_xX_s {
#define xX_MODE_INCLUDE 'x'
#define xX_MODE_EXCLUDE 'X'
int mode;
tcpr_list_t *list;
tcpr_cidr_t *cidr;
#define xX_TYPE_LIST 1
#define xX_TYPE_CIDR 2
int type;
} tcpr_xX_t;
/* number of ports 0-65535 */
#define NUM_PORTS 65536
typedef struct tcpr_services_s {
char tcp[NUM_PORTS];
char udp[NUM_PORTS];
} tcpr_services_t;
typedef struct tcpr_speed_s {
/* speed modifiers */
int mode;
#define SPEED_MULTIPLIER 1
#define SPEED_MBPSRATE 2
#define SPEED_PACKETRATE 3
#define SPEED_TOPSPEED 4
#define SPEED_ONEATATIME 5
COUNTER speed;
float multiplier;
int pps_multi;
} tcpr_speed_t;
#define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
#define DEFAULT_MTU 1500 /* Max Transmission Unit of standard ethernet
* don't forget *frames* are MTU + L2 header! */
#define MAXPACKET 65549 /* was 16436 linux loopback, but maybe something is bigger then
linux loopback */
#define MAX_SNAPLEN 65535 /* tell libpcap to capture the entire packet */
#define DNS_RESOLVE 1
#define DNS_DONT_RESOLVE 0
#define RESOLVE 0 /* disable dns lookups */
#define BPF_OPTIMIZE 1 /* default is to optimize bpf program */
#define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
#define DEFAULT_FUZZ_FACTOR 8
/* HP-UX already defines TRUE/FALSE */
#ifndef TRUE
typedef enum bool_e {
FALSE = 0,
TRUE
} bool_t;
#endif
#define EBUF_SIZE 1024 /* size of our error buffers */
#define MAC_SIZE 7 /* size of the mac[] buffer */
typedef enum pad_e {
PAD_PACKET,
TRUNC_PACKET
} pad_t;
#define DNS_QUERY_FLAG 0x8000
typedef enum direction_e {
DIR_UNKNOWN = -1,
DIR_CLIENT = 0,
DIR_SERVER = 1,
DIR_ANY = 2
} direction_t;
typedef enum tcpprep_mode_e {
ERROR_MODE, /* Some kind of error has occurred */
CIDR_MODE, /* single pass, CIDR netblock */
REGEX_MODE, /* single pass, regex */
PORT_MODE, /* single pass, use src/dst ports to split */
MAC_MODE, /* single pass, use src mac to split */
FIRST_MODE, /* single pass, use first seen to split */
AUTO_MODE, /* first pass through in auto mode */
ROUTER_MODE, /* second pass through in router mode */
BRIDGE_MODE, /* second pass through in bridge mode */
SERVER_MODE, /* second pass through in server (router) mode */
CLIENT_MODE /* second pass through in client (router) mode */
} tcpprep_mode_t;
#define BROADCAST_MAC "\xFF\xFF\xFF\xFF\xFF\xFF"
/* MAC macros for printf */
#define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
#define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
/* struct timeval print structs */
#ifdef HAVE_DARWIN
/* Darwin defines usec as an __int32_t, not unsigned long. */
#define TIMEVAL_FORMAT "%lus %dusec"
#else
#define TIMEVAL_FORMAT "%lus %luusec"
#endif
#define TIMESPEC_FORMAT "%lus %lunsec"
/* force a word or half-word swap on both Big and Little endian systems */
#ifndef SWAPLONG
#define SWAPLONG(y) \
((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
#endif
#ifndef SWAPSHORT
#define SWAPSHORT(y) \
( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
#endif
/* converts a 64bit int to network byte order */
#ifndef HAVE_NTOHLL
#ifdef WORDS_BIGENDIAN
#define ntohll(x) (x)
#define htonll(x) (x)
#else
/* stolen from http://www.codeproject.com/cpp/endianness.asp */
#define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
(unsigned int)ntohl(((int)(x >> 32))))
#define htonll(x) ntohll(x)
#endif /* WORDS_BIGENDIAN */
#endif
#define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
#define DEBUG_BASIC 2 /* limited debugging, one line per packet */
#define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
#define DEBUG_MORE 4 /* even more detail */
#define DEBUG_CODE 5 /* examines code & values, many lines per packet */
/* Win32 doesn't know about PF_INET6 */
#ifndef PF_INET6
#ifdef AF_INET6
#define PF_INET6 AF_INET6
#else
#define PF_INET6 30 /* stolen from OS/X */
#endif
#endif
/* convert IPv6 Extention Header Len value to bytes */
#define IPV6_EXTLEN_TO_BYTES(x) ((x * 4) + 8)
#ifndef HAVE_UINT8_T
typedef u_int8_t uint8_t
typedef u_int16_t uint16_t
typedef u_int32_t uint32_t
#endif
/* Support for flexible arrays. */
#undef __flexarr
#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
/* GCC 2.97 supports C99 flexible array members. */
# define __flexarr []
#else
# ifdef __GNUC__
# define __flexarr [0]
# else
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define __flexarr []
# elif defined(_WIN32)
/* MS VC++ */
# define __flexarr []
# else
/* Some other non-C99 compiler. Approximate with [1]. */
# define __flexarr [1]
# endif
# endif
#endif
/* Time converters */
#define SEC_TO_MILLISEC(x) (x * 1000)
#define SEC_TO_MICROSEC(x) (x * 1000000)
#define SEC_TO_NANOSEC(x) ((u_int64_t)x * 1000000000)
#define MILLISEC_TO_SEC(x) (x / 1000)
#define MICROSEC_TO_SEC(x) (x / 1000000)
#define NANOSEC_TO_SEC(x) ((u_int64_t)x / 1000000000)
#define TIMEVAL_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_usec / 1000))
#define TIMEVAL_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_usec)
#define TIMEVAL_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_usec * 1000))
#define TIMSTAMP_TO_MICROSEC(x) (TIMEVAL_TO_MICROSEC(x))
#define MILLISEC_TO_TIMEVAL(x, tv) \
do { \
(tv)->tv_sec = (x) / 1000; \
(tv)->tv_usec = (x * 1000) - ((tv)->tv_sec * 1000000); \
} while(0)
#define MICROSEC_TO_TIMEVAL(x, tv) \
do { \
(tv)->tv_sec = (x) / 1000000; \
(tv)->tv_usec = (x) - ((tv)->tv_sec * 1000000); \
} while(0)
#define NANOSEC_TO_TIMEVAL(x, tv) \
do { \
(tv)->tv_sec = (x) / 1000000000; \
(tv)->tv_usec = ((x) % 1000000000) / 1000; \
} while(0)
#define NANOSEC_TO_TIMESPEC(x, ts) \
do { \
(ts)->tv_sec = (x) / 1000000000; \
(ts)->tv_nsec = (x) % 1000000000; \
} while(0)
#define TIMESPEC_TO_MILLISEC(x) (((x)->tv_sec * 1000) + ((x)->tv_nsec / 1000000))
#define TIMESPEC_TO_MICROSEC(x) (((x)->tv_sec * 1000000) + (x)->tv_nsec / 1000)
#define TIMESPEC_TO_NANOSEC(x) ((u_int64_t)((x)->tv_sec * 1000000000) + ((u_int64_t)(x)->tv_nsec))
/*
* Help suppress some compiler warnings
* No problem if variable is actually used
*/
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif
#ifndef max
# define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#endif
#ifndef min
# define min(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _b : _a; })
#endif
#endif /* DEFINES */