2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010, 2011, 2012 Daniel Borkmann.
5 * Subject to the GPL, version 2.
17 #include "dissector.h"
18 #include "dissector_eth.h"
19 #include "dissector_80211.h"
21 int dissector_set_print_type(void *ptr
, int type
)
23 struct protocol
*proto
;
25 for (proto
= (struct protocol
*) ptr
; proto
; proto
= proto
->next
) {
27 case FNTTYPE_PRINT_NORM
:
28 proto
->process
= proto
->print_full
;
30 case FNTTYPE_PRINT_LESS
:
31 proto
->process
= proto
->print_less
;
33 case FNTTYPE_PRINT_HEX
:
34 case FNTTYPE_PRINT_ASCII
:
35 case FNTTYPE_PRINT_HEX_ASCII
:
36 case FNTTYPE_PRINT_NONE
:
38 proto
->process
= NULL
;
46 static void dissector_main(struct pkt_buff
*pkt
, struct protocol
*start
,
49 struct protocol
*proto
;
54 for (pkt
->proto
= start
; pkt
->proto
; ) {
55 if (unlikely(!pkt
->proto
->process
))
63 if (end
&& likely(end
->process
))
67 void dissector_entry_point(uint8_t *packet
, size_t len
, int linktype
, int mode
)
69 struct protocol
*proto_start
= NULL
;
70 struct protocol
*proto_end
= NULL
;
71 struct pkt_buff
*pkt
= NULL
;
73 if (mode
== FNTTYPE_PRINT_NONE
)
76 pkt
= pkt_alloc(packet
, len
);
80 proto_start
= dissector_get_ethernet_entry_point();
81 proto_end
= dissector_get_ethernet_exit_point();
83 case LINKTYPE_IEEE802_11
:
84 proto_start
= dissector_get_ieee80211_entry_point();
85 proto_end
= dissector_get_ieee80211_exit_point();
88 panic("Linktype not supported!\n");
91 dissector_main(pkt
, proto_start
, proto_end
);
94 case FNTTYPE_PRINT_HEX
:
97 case FNTTYPE_PRINT_ASCII
:
100 case FNTTYPE_PRINT_HEX_ASCII
:
109 void dissector_init_all(int fnttype
)
111 dissector_init_ethernet(fnttype
);
112 dissector_init_ieee80211(fnttype
);
115 void dissector_cleanup_all(void)
117 dissector_cleanup_ethernet();
118 dissector_cleanup_ieee80211();