netsniff-ng: refactor the code a bit
[netsniff-ng.git] / src / dissector.h
blob424f07ea6a459ba0b95a069dcdc32357c25e7cb6
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #ifndef DISSECTOR_H
9 #define DISSECTOR_H
11 #include <stdlib.h>
12 #include <stdint.h>
14 #include "ring.h"
15 #include "tprintf.h"
17 #define LINKTYPE_NULL 0 /* BSD loopback encapsulation */
18 #define LINKTYPE_EN10MB 1 /* Ethernet (10Mb) */
19 #define LINKTYPE_EN3MB 2 /* Experimental Ethernet (3Mb) */
20 #define LINKTYPE_AX25 3 /* Amateur Radio AX.25 */
21 #define LINKTYPE_PRONET 4 /* Proteon ProNET Token Ring */
22 #define LINKTYPE_CHAOS 5 /* Chaos */
23 #define LINKTYPE_IEEE802 6 /* 802.5 Token Ring */
24 #define LINKTYPE_ARCNET 7 /* ARCNET, with BSD-style header */
25 #define LINKTYPE_SLIP 8 /* Serial Line IP */
26 #define LINKTYPE_PPP 9 /* Point-to-point Protocol */
27 #define LINKTYPE_FDDI 10 /* FDDI */
28 #define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 wireless */
30 #define PRINT_NORM 0
31 #define PRINT_LESS 1
32 #define PRINT_HEX 2
33 #define PRINT_ASCII 3
34 #define PRINT_HEX_ASCII 4
35 #define PRINT_NONE 5
37 extern void dissector_init_all(int fnttype);
38 extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode);
39 extern void dissector_cleanup_all(void);
40 extern int dissector_set_print_type(void *ptr, int type);
42 static char *packet_types[]={
43 "<", /* Incoming */
44 "B", /* Broadcast */
45 "M", /* Multicast */
46 "P", /* Promisc */
47 ">", /* Outgoing */
48 "?", /* Unknown */
51 static inline void show_frame_hdr(struct frame_map *hdr, int mode,
52 enum ring_mode rmode)
54 if (mode == PRINT_NONE)
55 return;
57 switch (mode) {
58 case PRINT_LESS:
59 if (rmode == RING_MODE_INGRESS) {
60 tprintf("%s %d %u",
61 packet_types[hdr->s_ll.sll_pkttype],
62 hdr->s_ll.sll_ifindex, hdr->tp_h.tp_len);
63 } else {
64 tprintf("%u ", hdr->tp_h.tp_len);
66 break;
67 case PRINT_NORM:
68 case PRINT_HEX:
69 case PRINT_ASCII:
70 case PRINT_HEX_ASCII:
71 default:
72 if (rmode == RING_MODE_INGRESS) {
73 tprintf("%s %d %u %us.%uns\n",
74 packet_types[hdr->s_ll.sll_pkttype],
75 hdr->s_ll.sll_ifindex, hdr->tp_h.tp_len,
76 hdr->tp_h.tp_sec, hdr->tp_h.tp_nsec);
77 } else {
78 tprintf("%u %us.%uns\n", hdr->tp_h.tp_len,
79 hdr->tp_h.tp_sec, hdr->tp_h.tp_nsec);
81 break;
85 #endif /* DISSECTOR_H */