zsh: add netsniff-ng zsh auto completion support
[netsniff-ng.git] / dissector.h
blobd211e06af95aa4f550cb0cdf557f74ee8bef8e42
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"
16 #include "built_in.h"
18 #define PRINT_NORM 0
19 #define PRINT_LESS 1
20 #define PRINT_HEX 2
21 #define PRINT_ASCII 3
22 #define PRINT_HEX_ASCII 4
23 #define PRINT_NONE 5
25 static const char * const packet_types[256]={
26 "<", /* Incoming */
27 "B", /* Broadcast */
28 "M", /* Multicast */
29 "P", /* Promisc */
30 ">", /* Outgoing */
31 "?", /* Unknown */
34 extern char *if_indextoname(unsigned ifindex, char *ifname);
36 static inline const char *__show_ts_source(uint32_t status)
38 if (status & TP_STATUS_TS_RAW_HARDWARE)
39 return "(raw hw ts)";
40 else if (status & TP_STATUS_TS_SYS_HARDWARE)
41 return "(sys hw ts)";
42 else if (status & TP_STATUS_TS_SOFTWARE)
43 return "(sw ts)";
44 else
45 return "";
48 static inline void show_frame_hdr(struct frame_map *hdr, int mode)
50 char tmp[IFNAMSIZ];
52 if (mode == PRINT_NONE)
53 return;
55 switch (mode) {
56 case PRINT_LESS:
57 tprintf("%s %s %u",
58 packet_types[hdr->s_ll.sll_pkttype] ? : "?",
59 if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?",
60 hdr->tp_h.tp_len);
61 break;
62 default:
63 tprintf("%s %s %u %us.%uns %s\n",
64 packet_types[hdr->s_ll.sll_pkttype] ? : "?",
65 if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?",
66 hdr->tp_h.tp_len, hdr->tp_h.tp_sec,
67 hdr->tp_h.tp_nsec,
68 __show_ts_source(hdr->tp_h.tp_status));
69 break;
73 extern void dissector_init_all(int fnttype);
74 extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode);
75 extern void dissector_cleanup_all(void);
76 extern int dissector_set_print_type(void *ptr, int type);
78 #endif /* DISSECTOR_H */