Merge pull request #59 from electronjoe/graceful-SIGTERM-handling
[netsniff-ng-old.git] / dissector.h
blobfc2cd5ad42b6b844b099bd5f117705b335953c49
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #ifndef DISSECTOR_H
8 #define DISSECTOR_H
10 #include <stdlib.h>
11 #include <stdint.h>
13 #include "ring.h"
14 #include "tprintf.h"
15 #include "pcap_io.h"
17 #define PRINT_NORM 0
18 #define PRINT_LESS 1
19 #define PRINT_HEX 2
20 #define PRINT_ASCII 3
21 #define PRINT_HEX_ASCII 4
22 #define PRINT_NONE 5
24 static const char * const packet_types[256]={
25 "<", /* Incoming */
26 "B", /* Broadcast */
27 "M", /* Multicast */
28 "P", /* Promisc */
29 ">", /* Outgoing */
30 "?", /* Unknown */
33 extern char *if_indextoname(unsigned ifindex, char *ifname);
35 static inline void show_frame_hdr(struct frame_map *hdr, int mode)
37 char tmp[IFNAMSIZ];
39 if (mode == PRINT_NONE)
40 return;
42 switch (mode) {
43 case PRINT_LESS:
44 tprintf("%s %s %u",
45 packet_types[hdr->s_ll.sll_pkttype] ? : "?",
46 if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?",
47 hdr->tp_h.tp_len);
48 break;
49 default:
50 tprintf("%s %s %u %us.%uns\n",
51 packet_types[hdr->s_ll.sll_pkttype] ? : "?",
52 if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?",
53 hdr->tp_h.tp_len, hdr->tp_h.tp_sec,
54 hdr->tp_h.tp_nsec);
55 break;
59 extern void dissector_init_all(int fnttype);
60 extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode);
61 extern void dissector_cleanup_all(void);
62 extern int dissector_set_print_type(void *ptr, int type);
64 #endif /* DISSECTOR_H */