Update portability notes.
[darkstat] / decode.h
1 /* darkstat 3
2 * copyright (c) 2001-2012 Emil Mikulic.
3 *
4 * decode.h: packet decoding.
5 *
6 * You may use, modify and redistribute this file under the terms of the
7 * GNU General Public License version 2. (see COPYING.GPL)
8 */
9 #ifndef __DARKSTAT_DECODE_H
10 #define __DARKSTAT_DECODE_H
11
12 #include "addr.h"
13
14 #ifndef ETHER_ADDR_LEN
15 # define ETHER_ADDR_LEN 6
16 #endif
17
18 #define IPPROTO_INVALID 254 /* special: means don't do proto accounting */
19
20 #ifndef IPPROTO_OSPF
21 # define IPPROTO_OSPF 89
22 #endif
23
24 #define PPPOE_HDR_LEN 8
25
26 /* Decoding creates a summary which is passed to accounting. */
27 struct pktsummary {
28 /* Fields are in host byte order (except IPs) */
29 struct addr src, dst;
30 uint16_t len;
31 uint8_t proto; /* IPPROTO_INVALID means don't do proto accounting */
32 uint8_t tcp_flags; /* only for TCP */
33 uint16_t src_port, dst_port; /* only for TCP, UDP */
34 uint8_t src_mac[ETHER_ADDR_LEN], /* only for Ethernet */
35 dst_mac[ETHER_ADDR_LEN]; /* only for Ethernet */
36 };
37
38 struct pcap_pkthdr; /* from pcap.h */
39
40 #define DECODER_ARGS const struct pcap_pkthdr *pheader, \
41 const u_char *pdata, \
42 struct pktsummary *sm
43
44 /* Returns 0 on decode failure (meaning accounting should not be performed) */
45 typedef int (decoder_fn)(DECODER_ARGS);
46
47 struct linkhdr {
48 int linktype;
49 unsigned int hdrlen;
50 decoder_fn *decoder;
51 };
52
53 const struct linkhdr *getlinkhdr(const int linktype);
54 int getsnaplen(const struct linkhdr *lh);
55
56 #endif /* __DARKSTAT_DECODE_H */
57 /* vim:set ts=3 sw=3 tw=78 expandtab: */