2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010, 2011, 2012 Daniel Borkmann.
4 * Subject to the GPL, version 2.
15 #include "dissector.h"
16 #include "dissector_eth.h"
17 #include "dissector_80211.h"
18 #include "dissector_netlink.h"
21 int dissector_set_print_type(void *ptr
, int type
)
23 struct protocol
*proto
;
25 for (proto
= ptr
; proto
; proto
= proto
->next
) {
28 proto
->process
= proto
->print_full
;
31 proto
->process
= proto
->print_less
;
34 proto
->process
= NULL
;
42 static void dissector_main(struct pkt_buff
*pkt
, struct protocol
*start
,
45 struct protocol
*proto
;
50 for (pkt
->proto
= start
; pkt
->proto
; ) {
51 if (unlikely(!pkt
->proto
->process
))
59 if (end
&& likely(end
->process
))
63 void dissector_entry_point(uint8_t *packet
, size_t len
, int linktype
, int mode
)
65 struct protocol
*proto_start
, *proto_end
;
68 if (mode
== PRINT_NONE
)
71 pkt
= pkt_alloc(packet
, len
);
75 case ___constant_swab32(LINKTYPE_EN10MB
):
76 proto_start
= dissector_get_ethernet_entry_point();
77 proto_end
= dissector_get_ethernet_exit_point();
79 case LINKTYPE_IEEE802_11
:
80 case ___constant_swab32(LINKTYPE_IEEE802_11
):
81 proto_start
= dissector_get_ieee80211_entry_point();
82 proto_end
= dissector_get_ieee80211_exit_point();
84 case LINKTYPE_NETLINK
:
85 case ___constant_swab32(LINKTYPE_NETLINK
):
86 proto_start
= dissector_get_netlink_entry_point();
87 proto_end
= dissector_get_netlink_exit_point();
90 proto_start
= &none_ops
;
95 dissector_main(pkt
, proto_start
, proto_end
);
104 case PRINT_HEX_ASCII
:
113 void dissector_init_all(int fnttype
)
115 dissector_init_ethernet(fnttype
);
116 dissector_init_ieee80211(fnttype
);
117 dissector_init_netlink(fnttype
);
120 void dissector_cleanup_all(void)
122 dissector_cleanup_ethernet();
123 dissector_cleanup_ieee80211();
124 dissector_cleanup_netlink();