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.
13 #include "dissector.h"
14 #include "dissector_80211.h"
18 struct hash_table ieee80211_lay2
;
20 static struct hash_table ieee80211_oui
;
25 struct vendor_id
*next
;
28 /* Note: this macro only applies to the lookup_* functions here in this file,
29 * mainly to remove redundand code. */
30 #define __do_lookup_inline(id, struct_name, hash_ptr, struct_member) \
32 struct struct_name *entry = lookup_hash(id, hash_ptr); \
33 while (entry && id != entry->id) \
34 entry = entry->next; \
35 (entry && id == entry->id ? entry->struct_member : "Unknown");\
38 char *lookup_vendor(unsigned int id
)
40 return __do_lookup_inline(id
, vendor_id
, &ieee80211_oui
, vendor
);
43 static inline void dissector_init_entry(int type
)
45 dissector_set_print_type(&ieee80211_mac_ops
, type
);
48 static inline void dissector_init_exit(int type
)
50 dissector_set_print_type(&none_ops
, type
);
53 static void dissector_init_layer_2(int type
)
55 init_hash(&ieee80211_lay2
);
56 // INSERT_HASH_PROTOS(arp_ops, eth_lay2);
57 // INSERT_HASH_PROTOS(vlan_ops, eth_lay2);
58 // INSERT_HASH_PROTOS(ipv4_ops, eth_lay2);
59 // INSERT_HASH_PROTOS(ipv6_ops, eth_lay2);
60 for_each_hash_int(&ieee80211_lay2
, dissector_set_print_type
, type
);
63 static void dissector_init_oui(void)
67 struct vendor_id
*ven
;
69 fp
= fopen("/etc/netsniff-ng/oui.conf", "r");
71 panic("No /etc/netsniff-ng/oui.conf found!\n");
72 memset(buff
, 0, sizeof(buff
));
73 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
74 buff
[sizeof(buff
) - 1] = 0;
75 ven
= xmalloc(sizeof(*ven
));
78 ptr
= getuint(ptr
, &ven
->id
);
80 ptr
= skipchar(ptr
, ',');
82 ptr
= strtrim_right(ptr
, '\n');
83 ptr
= strtrim_right(ptr
, ' ');
84 ven
->vendor
= xstrdup(ptr
);
86 pos
= insert_hash(ven
->id
, ven
, &ieee80211_oui
);
91 memset(buff
, 0, sizeof(buff
));
96 static int dissector_cleanup_oui(void *ptr
)
98 struct vendor_id
*tmp
, *v
= ptr
;
101 while ((tmp
= v
->next
)) {
111 void dissector_init_ieee80211(int fnttype
)
113 dissector_init_entry(fnttype
);
114 dissector_init_layer_2(fnttype
);
115 dissector_init_exit(fnttype
);
116 dissector_init_oui();
119 void dissector_cleanup_ieee80211(void)
121 free_hash(&ieee80211_lay2
);
122 for_each_hash(&ieee80211_oui
, dissector_cleanup_oui
);
123 free_hash(&ieee80211_oui
);