Small IPv6 corrections and an IPv6 hash function.
[darkstat] / decode.h
1 /* darkstat 3
2 * copyright (c) 2001-2009 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
10 #include <pcap.h>
11 #include <netinet/in_systm.h> /* n_time */
12 #define __USE_GNU 1
13 #include <netinet/in.h> /* in_addr_t */
14 #include <netinet/ip.h> /* struct ip */
15
16 #define PPP_HDR_LEN 4
17 #define FDDI_HDR_LEN 21
18 #define IP_HDR_LEN sizeof(struct ip)
19 #define IPV6_HDR_LEN sizeof(struct ip6_hdr)
20 #define TCP_HDR_LEN sizeof(struct tcphdr)
21 #define UDP_HDR_LEN sizeof(struct udphdr)
22 #define NULL_HDR_LEN 4
23 #define PPPOE_HDR_LEN 8
24 #define SLL_HDR_LEN 16
25 #define RAW_HDR_LEN 0
26
27 #ifndef ETHER_ADDR_LEN
28 #define ETHER_ADDR_LEN 6
29 #endif
30
31 typedef struct {
32 int linktype;
33 unsigned int hdrlen;
34 pcap_handler handler;
35 } linkhdr_t;
36
37 const linkhdr_t *getlinkhdr(int linktype);
38 int getsnaplen(const linkhdr_t *lh);
39 char *ip_to_str(const in_addr_t ip);
40 char *ip6_to_str(const struct in6_addr *ip6);
41
42 typedef struct {
43 /* Fields are in host byte order (except IPs) */
44 union {
45 in_addr_t src_ip;
46 struct in6_addr src_ip6;
47 };
48 union {
49 in_addr_t dest_ip;
50 struct in6_addr dest_ip6;
51 };
52 time_t time;
53 uint16_t len;
54 sa_family_t af; /* AF_{UNSPEC, INET, INET6} */
55 uint8_t proto; /* IPPROTO_{TCP, UDP, ICMP} */
56 uint8_t tcp_flags; /* only for TCP */
57 uint16_t src_port, dest_port; /* only for TCP, UDP */
58 uint8_t src_mac[ETHER_ADDR_LEN],
59 dst_mac[ETHER_ADDR_LEN]; /* only for Ethernet */
60 } pktsummary;
61
62 /* vim:set ts=3 sw=3 tw=78 expandtab: */