Make headers self-sufficient.
[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 #ifndef __DARKSTAT_DECODE_H
10 #define __DARKSTAT_DECODE_H
11
12 #include <pcap.h>
13 #include <netinet/in_systm.h> /* n_time */
14 #define __USE_GNU 1
15 #include <netinet/in.h> /* for <netinet/ip.h> */
16 #include <netinet/ip.h> /* struct ip */
17
18 #include "hosts_db.h" /* addr46 */
19
20 #define PPP_HDR_LEN 4
21 #define FDDI_HDR_LEN 21
22 #define IP_HDR_LEN sizeof(struct ip)
23 #define IPV6_HDR_LEN sizeof(struct ip6_hdr)
24 #define TCP_HDR_LEN sizeof(struct tcphdr)
25 #define UDP_HDR_LEN sizeof(struct udphdr)
26 #define NULL_HDR_LEN 4
27 #define PPPOE_HDR_LEN 8
28 #define SLL_HDR_LEN 16
29 #define RAW_HDR_LEN 0
30
31 #ifndef ETHER_ADDR_LEN
32 #define ETHER_ADDR_LEN 6
33 #endif
34
35 #ifndef IPPROTO_OSPF
36 # define IPPROTO_OSPF 89
37 #endif
38
39 struct linkhdr {
40 int linktype;
41 unsigned int hdrlen;
42 pcap_handler handler;
43 };
44
45 const struct linkhdr *getlinkhdr(const int linktype);
46 int getsnaplen(const struct linkhdr *lh);
47 char *ip_to_str(const struct addr46 *const ip);
48 char *ip_to_str_af(const void *const addr, sa_family_t af);
49
50 typedef struct {
51 /* Fields are in host byte order (except IPs) */
52 union {
53 struct in_addr src_ip;
54 struct in6_addr src_ip6;
55 };
56 union {
57 struct in_addr dest_ip;
58 struct in6_addr dest_ip6;
59 };
60 time_t time;
61 uint16_t len;
62 sa_family_t af; /* AF_{UNSPEC, INET, INET6} */
63 uint8_t proto; /* IPPROTO_{TCP, UDP, ICMP} */
64 uint8_t tcp_flags; /* only for TCP */
65 uint16_t src_port, dest_port; /* only for TCP, UDP */
66 uint8_t src_mac[ETHER_ADDR_LEN],
67 dst_mac[ETHER_ADDR_LEN]; /* only for Ethernet */
68 } pktsummary;
69
70 #endif /* __DARKSTAT_DECODE_H */
71 /* vim:set ts=3 sw=3 tw=78 expandtab: */