Imported Upstream version 3.0.717
[darkstat-debian] / decode.h
index 35cb42a..cc4bd55 100644 (file)
--- a/decode.h
+++ b/decode.h
@@ -9,55 +9,49 @@
 #ifndef __DARKSTAT_DECODE_H
 #define __DARKSTAT_DECODE_H
 
-#include <pcap.h>
-#include <netinet/in_systm.h>  /* n_time */
-#define __USE_GNU 1
-#include <netinet/in.h> /* for <netinet/ip.h>  */
-#include <netinet/ip.h> /* 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: */