Initial import
[sliver-openvswitch.git] / datapath / tests / ofp_pcap.h
1 #ifndef OFP_PCAP_H
2 #define OFP_PCAP_H
3
4 #include <stdint.h>
5 #include <sys/time.h>
6 #include <stdio.h>
7
8 #define OFP_PCAP_VERSION_MAJOR 2
9 #define OFP_PCAP_VERSION_MINOR 4
10
11 #define TCPDUMP_MAGIC 0xa1b2c3d4
12
13 #define OFP_LINKTYPE_ETHERNET 1
14
15 #define OFP_PCAP_ERRBUF_SIZE  256
16
17 /* Swap the byte order regardless of the architecture */
18 #define SWAPLONG(x) \
19         ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | (((x)&0xff0000)>>8) | (((x)&0xff000000)>>24))
20 #define SWAPSHORT(x) \
21         ((((x)&0xff)<<8) | (((x)&0xff00)>>8))
22
23 struct ofp_pcap {
24         FILE *fp;               /* File pointer to currently processed file */
25         int swapped;            /* Indicate whether endian-ness needs to change */
26         char *buf;              /* Buffer to hold packet data */
27         size_t bufsize;         /* Size of buffer */
28         char *errbuf;               /* Pointer to buffer to hold error message */
29 };
30
31 struct pcap_file_header {
32         uint32_t magic;         /* Magic number */
33         uint16_t version_major; /* Version number major */
34         uint16_t version_minor; /* Version number minor */
35         int32_t  thiszone;      /* Gmt to local correction */
36         uint32_t sigfigs;       /* Accuracy of timestamps */
37         uint32_t snaplen;       /* Max length saved portion of each pkt */
38         uint32_t linktype;      /* Data link type (LINKTYPE_*) */
39 };
40
41 /*
42  * This is a timeval as stored in disk in a dumpfile.
43  * It has to use the same types everywhere, independent of the actual
44  * `struct timeval'
45  */
46 struct pcap_timeval {
47         int32_t tv_sec;         /* Seconds */
48         int32_t tv_usec;        /* Microseconds */
49 };
50
51 /*
52  * How a `pcap_pkthdr' is actually stored in the dumpfile.
53  */
54 struct pcap_pkthdr {
55         struct pcap_timeval ts; /* Time stamp */
56         uint32_t caplen;        /* Length of portion present */
57         uint32_t len;           /* Length this packet (off wire) */
58 };
59
60 int ofp_pcap_open(struct ofp_pcap *p, const char *fname, char *errbuf);
61 char *ofp_pcap_next(struct ofp_pcap *p, struct pcap_pkthdr *hdr);
62 void ofp_pcap_close(struct ofp_pcap *p);
63
64 #endif /* ofp_pcap.h */