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_sll.h"
18 #include "dissector_80211.h"
19 #include "dissector_netlink.h"
22 int dissector_set_print_type(void *ptr
, int type
)
24 struct protocol
*proto
;
26 for (proto
= ptr
; proto
; proto
= proto
->next
) {
29 proto
->process
= proto
->print_full
;
32 proto
->process
= proto
->print_less
;
35 proto
->process
= NULL
;
43 static void dissector_main(struct pkt_buff
*pkt
, struct protocol
*start
,
46 struct protocol
*dissector
;
51 for (pkt
->dissector
= start
; pkt
->dissector
; ) {
52 if (unlikely(!pkt
->dissector
->process
))
55 dissector
= pkt
->dissector
;
56 pkt
->dissector
= NULL
;
57 dissector
->process(pkt
);
60 if (end
&& likely(end
->process
))
64 void dissector_entry_point(uint8_t *packet
, size_t len
, int linktype
, int mode
,
65 struct sockaddr_ll
*sll
)
67 struct protocol
*proto_start
, *proto_end
;
70 if (mode
== PRINT_NONE
)
73 pkt
= pkt_alloc(packet
, len
);
74 pkt
->link_type
= linktype
;
79 case ___constant_swab32(LINKTYPE_EN10MB
):
80 proto_start
= dissector_get_ethernet_entry_point();
81 proto_end
= dissector_get_ethernet_exit_point();
83 case LINKTYPE_IEEE802_11_RADIOTAP
:
84 case ___constant_swab32(LINKTYPE_IEEE802_11_RADIOTAP
):
85 case LINKTYPE_IEEE802_11
:
86 case ___constant_swab32(LINKTYPE_IEEE802_11
):
87 proto_start
= dissector_get_ieee80211_entry_point();
88 proto_end
= dissector_get_ieee80211_exit_point();
90 case LINKTYPE_NETLINK
:
91 case ___constant_swab32(LINKTYPE_NETLINK
):
92 proto_start
= dissector_get_netlink_entry_point();
93 proto_end
= dissector_get_netlink_exit_point();
95 case LINKTYPE_LINUX_SLL
:
96 case ___constant_swab32(LINKTYPE_LINUX_SLL
):
97 proto_start
= dissector_get_sll_entry_point();
98 proto_end
= dissector_get_sll_exit_point();
101 proto_start
= &none_ops
;
106 dissector_main(pkt
, proto_start
, proto_end
);
115 case PRINT_HEX_ASCII
:
124 void dissector_init_all(int fnttype
)
126 dissector_init_ethernet(fnttype
);
127 dissector_init_ieee80211(fnttype
);
128 dissector_init_netlink(fnttype
);
129 dissector_init_sll(fnttype
);
132 void dissector_cleanup_all(void)
134 dissector_cleanup_ethernet();
135 dissector_cleanup_ieee80211();
136 dissector_cleanup_netlink();
137 dissector_cleanup_sll();