-
Notifications
You must be signed in to change notification settings - Fork 2
/
pcap-tools.h
46 lines (40 loc) · 1.35 KB
/
pcap-tools.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
#ifndef PCAP_TOOLS_H
#define PCAP_TOOLS_H 1
/* Convert the network order 32 bit integer pointed to by p to host order.
* p does not have to be aligned. */
#ifndef nptohl
#define nptohl(p) \
((((uint8_t*)(p))[0] << 24) | \
(((uint8_t*)(p))[1] << 16) | \
(((uint8_t*)(p))[2] << 8) | \
((uint8_t*)(p))[3])
#endif
/* Copy the host order 32 bit integer in x into the memory pointed to by p
* in network order. p does not have to be aligned. */
#ifndef htonpl
#define htonpl(p, x) \
do { \
((uint8_t*)(p))[0] = (x & 0xFF000000) >> 24; \
((uint8_t*)(p))[1] = (x & 0x00FF0000) >> 16; \
((uint8_t*)(p))[2] = (x & 0x0000FF00) >> 8; \
((uint8_t*)(p))[3] = (x & 0x000000FF) >> 0; \
} while (0)
#endif
/* Convert the network order 16 bit integer pointed to by p to host order.
* p does not have to be aligned. */
#ifndef nptohs
#define nptohs(p) \
((((uint8_t*)(p))[0] << 8) | ((uint8_t*)(p))[1])
#endif
/* Copy the host order 16 bit integer in x into the memory pointed to by p
* in network order. p does not have to be aligned. */
#ifndef htonps
#define htonps(p, x) \
do { \
((uint8_t*)(p))[0] = (x & 0xFF00) >> 8; \
((uint8_t*)(p))[1] = (x & 0x00FF) >> 0; \
} while (0)
#endif
pcap_t * my_pcap_open_offline(const char *pcapfile);
void my_pcap_close_offline(pcap_t *in);
#endif /* PCAP_TOOLS_H */