dissector: remove cases that go into default
[netsniff-ng.git] / dissector.c
blob0eb01b405cec9ee04698aa745154012f6bc8ca57
1 /*
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.
6 */
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <unistd.h>
12 #include "built_in.h"
13 #include "tprintf.h"
14 #include "pkt_buff.h"
15 #include "proto.h"
16 #include "protos.h"
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 = ptr; proto; proto = proto->next) {
26 switch (type) {
27 case PRINT_NORM:
28 proto->process = proto->print_full;
29 break;
30 case PRINT_LESS:
31 proto->process = proto->print_less;
32 break;
33 default:
34 proto->process = NULL;
35 break;
39 return 0;
42 static void dissector_main(struct pkt_buff *pkt, struct protocol *start,
43 struct protocol *end)
45 struct protocol *proto;
47 if (!start)
48 return;
50 for (pkt->proto = start; pkt->proto; ) {
51 if (unlikely(!pkt->proto->process))
52 break;
54 proto = pkt->proto;
55 pkt->proto = NULL;
56 proto->process(pkt);
59 if (end && likely(end->process))
60 end->process(pkt);
63 void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode)
65 struct protocol *proto_start = NULL;
66 struct protocol *proto_end = NULL;
67 struct pkt_buff *pkt = NULL;
69 if (mode == PRINT_NONE)
70 return;
72 pkt = pkt_alloc(packet, len);
74 switch (linktype) {
75 case LINKTYPE_EN10MB:
76 case ___constant_swab32(LINKTYPE_EN10MB):
77 proto_start = dissector_get_ethernet_entry_point();
78 proto_end = dissector_get_ethernet_exit_point();
79 break;
80 case LINKTYPE_IEEE802_11:
81 case ___constant_swab32(LINKTYPE_IEEE802_11):
82 proto_start = dissector_get_ieee80211_entry_point();
83 proto_end = dissector_get_ieee80211_exit_point();
84 break;
85 default:
86 panic("Linktype not supported!\n");
89 dissector_main(pkt, proto_start, proto_end);
91 switch (mode) {
92 case PRINT_HEX:
93 hex(pkt);
94 break;
95 case PRINT_ASCII:
96 ascii(pkt);
97 break;
98 case PRINT_HEX_ASCII:
99 hex_ascii(pkt);
100 break;
103 tprintf_flush();
104 pkt_free(pkt);
107 void dissector_init_all(int fnttype)
109 dissector_init_ethernet(fnttype);
110 dissector_init_ieee80211(fnttype);
113 void dissector_cleanup_all(void)
115 dissector_cleanup_ethernet();
116 dissector_cleanup_ieee80211();