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.
14 #include "dissector.h"
15 #include "dissector_eth.h"
16 #include "proto_struct.h"
18 /* TODO: Refactoring duplicate code, clean up code, also in protos */
19 int dissector_set_print_norm(void *ptr
)
21 struct protocol
*proto
= (struct protocol
*) ptr
;
22 while (proto
!= NULL
) {
23 proto
->process
= proto
->print_full
;
29 int dissector_set_print_less(void *ptr
)
31 struct protocol
*proto
= (struct protocol
*) ptr
;
32 while (proto
!= NULL
) {
33 proto
->process
= proto
->print_less
;
39 int dissector_set_print_none(void *ptr
)
41 struct protocol
*proto
= (struct protocol
*) ptr
;
42 while (proto
!= NULL
) {
43 proto
->process
= NULL
;
49 int dissector_set_print_payload(void *ptr
)
51 struct protocol
*proto
= (struct protocol
*) ptr
;
52 while (proto
!= NULL
) {
53 proto
->process
= proto
->print_pay_ascii
;
59 int dissector_set_print_payload_hex(void *ptr
)
61 struct protocol
*proto
= (struct protocol
*) ptr
;
62 while (proto
!= NULL
) {
63 proto
->process
= proto
->print_pay_hex
;
69 int dissector_set_print_c_style(void *ptr
)
71 struct protocol
*proto
= (struct protocol
*) ptr
;
72 while (proto
!= NULL
) {
73 proto
->process
= proto
->print_all_cstyle
;
79 int dissector_set_print_all_hex(void *ptr
)
81 struct protocol
*proto
= (struct protocol
*) ptr
;
82 while (proto
!= NULL
) {
83 proto
->process
= proto
->print_all_hex
;
89 int dissector_set_print_no_payload(void *ptr
)
91 struct protocol
*proto
= (struct protocol
*) ptr
;
92 while (proto
!= NULL
) {
93 proto
->process
= proto
->print_pay_none
;
100 * The main loop of the dissector. This is designed generic, so it doesn't
101 * know the underlying linktype.
103 static void dissector_main(uint8_t *packet
, size_t len
,
104 struct protocol
*start
, struct protocol
*end
)
108 struct hash_table
*table
;
109 struct protocol
*proto
= start
;
111 while (proto
!= NULL
) {
114 if (unlikely(!proto
->process
))
119 proto
->process(packet
, off
);
120 if (unlikely(!proto
->proto_next
))
122 proto
->proto_next(packet
, len
, &table
, &key
, &off
);
123 if (unlikely(!table
))
125 proto
= lookup_hash(key
, table
);
126 while (proto
&& key
!= proto
->key
)
132 if (likely(end
->process
))
133 end
->process(packet
, len
);
138 * This is the entry point for the packet dissector machine. It is
139 * developed for being as generic as possible, so that other linktypes
140 * can be implemented, too. Only the direct entry point functions
141 * that are linktype specific are called.
143 void dissector_entry_point(uint8_t *packet
, size_t len
, int linktype
)
145 struct protocol
*proto_start
= NULL
;
146 struct protocol
*proto_end
= NULL
;
149 case LINKTYPE_EN10MB
:
150 proto_start
= dissector_get_ethernet_entry_point();
151 proto_end
= dissector_get_ethernet_exit_point();
157 dissector_main(packet
, len
, proto_start
, proto_end
);
161 * Initialization routines for all linktypes.
163 void dissector_init_all(int fnttype
)
165 dissector_init_ethernet(fnttype
);
169 * Garbage collection routines for all linktypes.
171 void dissector_cleanup_all(void)
173 dissector_cleanup_ethernet();