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