ifpps: Rename variable containing top number of CPUs
[netsniff-ng.git] / dissector.h
blob2c2c128f3b46b1342440544677bb6a0842c9ec09
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 <linux/if_packet.h>
14 #include "ring.h"
15 #include "tprintf.h"
16 #include "pcap_io.h"
17 #include "built_in.h"
19 #define PRINT_NORM 0
20 #define PRINT_LESS 1
21 #define PRINT_HEX 2
22 #define PRINT_ASCII 3
23 #define PRINT_HEX_ASCII 4
24 #define PRINT_NONE 5
26 static const char * const packet_types[256]={
27 "<", /* Incoming */
28 "B", /* Broadcast */
29 "M", /* Multicast */
30 "P", /* Promisc */
31 ">", /* Outgoing */
32 "?", /* Unknown */
35 extern char *if_indextoname(unsigned ifindex, char *ifname);
37 static inline const char *__show_ts_source(uint32_t status)
39 if (status & TP_STATUS_TS_RAW_HARDWARE)
40 return "(raw hw ts)";
41 else if (status & TP_STATUS_TS_SYS_HARDWARE)
42 return "(sys hw ts)";
43 else if (status & TP_STATUS_TS_SOFTWARE)
44 return "(sw ts)";
45 else
46 return "";
49 static inline void __show_frame_hdr(struct sockaddr_ll *s_ll,
50 void *raw, int mode, bool v3)
52 char tmp[IFNAMSIZ];
53 union tpacket_uhdr hdr;
55 if (mode == PRINT_NONE)
56 return;
58 hdr.raw = raw;
60 switch (mode) {
61 case PRINT_LESS:
62 tprintf("%s %s %u",
63 packet_types[s_ll->sll_pkttype] ? : "?",
64 if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
65 v3 ? hdr.h3->tp_len : hdr.h2->tp_len);
66 break;
67 default:
68 tprintf("%s %s %u %us.%uns %s\n",
69 packet_types[s_ll->sll_pkttype] ? : "?",
70 if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
71 v3 ? hdr.h3->tp_len : hdr.h2->tp_len,
72 v3 ? hdr.h3->tp_sec : hdr.h2->tp_sec,
73 v3 ? hdr.h3->tp_nsec : hdr.h2->tp_nsec,
74 v3 ? "" : __show_ts_source(hdr.h2->tp_status));
75 break;
79 static inline void show_frame_hdr(struct frame_map *hdr, int mode)
81 __show_frame_hdr(&hdr->s_ll, &hdr->tp_h, mode, false);
84 extern void dissector_init_all(int fnttype);
85 extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode);
86 extern void dissector_cleanup_all(void);
87 extern int dissector_set_print_type(void *ptr, int type);
89 #endif /* DISSECTOR_H */