dev: Integrate `promisc' module into `dev' module
[netsniff-ng.git] / dissector.h
blobe26c235c9b19e59b539e480b5a21503777c85fab
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>
12 #include <sys/socket.h>
13 #include <linux/if_packet.h>
14 #include <linux/if.h>
16 #include "ring.h"
17 #include "tprintf.h"
18 #include "pcap_io.h"
19 #include "built_in.h"
21 #define PRINT_NORM 0
22 #define PRINT_LESS 1
23 #define PRINT_HEX 2
24 #define PRINT_ASCII 3
25 #define PRINT_HEX_ASCII 4
26 #define PRINT_NONE 5
28 extern char *if_indextoname(unsigned ifindex, char *ifname);
30 static const char * const packet_types[256] = {
31 [PACKET_HOST] = "<", /* Incoming */
32 [PACKET_BROADCAST] = "B", /* Broadcast */
33 [PACKET_MULTICAST] = "M", /* Multicast */
34 [PACKET_OTHERHOST] = "P", /* Promisc */
35 [PACKET_OUTGOING] = ">", /* Outgoing */
36 "?", /* Unknown */
39 static inline const char *__show_ts_source(uint32_t status)
41 if (status & TP_STATUS_TS_RAW_HARDWARE)
42 return "(raw hw ts)";
43 else if (status & TP_STATUS_TS_SYS_HARDWARE)
44 return "(sys hw ts)";
45 else if (status & TP_STATUS_TS_SOFTWARE)
46 return "(sw ts)";
47 else
48 return "";
51 static inline void __show_frame_hdr(struct sockaddr_ll *s_ll,
52 void *raw, int mode, bool v3)
54 char tmp[IFNAMSIZ];
55 union tpacket_uhdr hdr;
57 if (mode == PRINT_NONE)
58 return;
60 hdr.raw = raw;
61 switch (mode) {
62 case PRINT_LESS:
63 tprintf("%s %s %u",
64 packet_types[s_ll->sll_pkttype] ? : "?",
65 if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
66 v3 ? hdr.h3->tp_len : hdr.h2->tp_len);
67 break;
68 default:
69 tprintf("%s %s %u %us.%uns %s\n",
70 packet_types[s_ll->sll_pkttype] ? : "?",
71 if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
72 v3 ? hdr.h3->tp_len : hdr.h2->tp_len,
73 v3 ? hdr.h3->tp_sec : hdr.h2->tp_sec,
74 v3 ? hdr.h3->tp_nsec : hdr.h2->tp_nsec,
75 v3 ? "" : __show_ts_source(hdr.h2->tp_status));
76 break;
80 static inline void show_frame_hdr(struct frame_map *hdr, int mode)
82 __show_frame_hdr(&hdr->s_ll, &hdr->tp_h, mode, false);
85 extern void dissector_init_all(int fnttype);
86 extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode);
87 extern void dissector_cleanup_all(void);
88 extern int dissector_set_print_type(void *ptr, int type);
90 #endif /* DISSECTOR_H */