X-Git-Url: https://unix4lyfe.org/gitweb/darkstat-debian/blobdiff_plain/a1e8056c92203d02860d719abb1d562453896da8..4da209d9116b41ab59eeedc5823bc2cb64b5bc3e:/decode.h diff --git a/decode.h b/decode.h index 35cb42a..cc4bd55 100644 --- a/decode.h +++ b/decode.h @@ -9,55 +9,49 @@ #ifndef __DARKSTAT_DECODE_H #define __DARKSTAT_DECODE_H -#include -#include /* n_time */ -#define __USE_GNU 1 -#include /* for */ -#include /* struct ip */ - #include "addr.h" -#define PPP_HDR_LEN 4 -#define FDDI_HDR_LEN 21 -#define IP_HDR_LEN sizeof(struct ip) -#define IPV6_HDR_LEN sizeof(struct ip6_hdr) -#define TCP_HDR_LEN sizeof(struct tcphdr) -#define UDP_HDR_LEN sizeof(struct udphdr) -#define NULL_HDR_LEN 4 -#define PPPOE_HDR_LEN 8 -#define SLL_HDR_LEN 16 -#define RAW_HDR_LEN 0 - #ifndef ETHER_ADDR_LEN -#define ETHER_ADDR_LEN 6 +# define ETHER_ADDR_LEN 6 #endif +#define IPPROTO_INVALID 254 /* special: means don't do proto accounting */ + #ifndef IPPROTO_OSPF -#define IPPROTO_OSPF 89 +# define IPPROTO_OSPF 89 #endif -#define IPPROTO_INVALID 254 /* don't do proto accounting */ - -struct linkhdr { - int linktype; - unsigned int hdrlen; - pcap_handler handler; -}; - -const struct linkhdr *getlinkhdr(const int linktype); -int getsnaplen(const struct linkhdr *lh); +#define PPPOE_HDR_LEN 8 +/* Decoding creates a summary which is passed to accounting. */ struct pktsummary { /* Fields are in host byte order (except IPs) */ struct addr src, dst; - time_t time; uint16_t len; - uint8_t proto; /* IPPROTO_{TCP, UDP, ICMP} */ + uint8_t proto; /* IPPROTO_INVALID means don't do proto accounting */ uint8_t tcp_flags; /* only for TCP */ uint16_t src_port, dst_port; /* only for TCP, UDP */ - uint8_t src_mac[ETHER_ADDR_LEN], + uint8_t src_mac[ETHER_ADDR_LEN], /* only for Ethernet */ dst_mac[ETHER_ADDR_LEN]; /* only for Ethernet */ }; +struct pcap_pkthdr; /* from pcap.h */ + +#define DECODER_ARGS const struct pcap_pkthdr *pheader, \ + const u_char *pdata, \ + struct pktsummary *sm + +/* Returns 0 on decode failure (meaning accounting should not be performed) */ +typedef int (decoder_fn)(DECODER_ARGS); + +struct linkhdr { + int linktype; + unsigned int hdrlen; + decoder_fn *decoder; +}; + +const struct linkhdr *getlinkhdr(const int linktype); +int getsnaplen(const struct linkhdr *lh); + #endif /* __DARKSTAT_DECODE_H */ /* vim:set ts=3 sw=3 tw=78 expandtab: */