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.
15 static struct hash_table oui
;
16 static int initialized
= 0;
21 struct vendor_id
*next
;
24 /* Note: this macro only applies to the lookup_* functions here in this file,
25 * mainly to remove redundand code. */
26 #define __do_lookup_inline(id, struct_name, hash_ptr, struct_member) \
28 struct struct_name *entry = lookup_hash(id, hash_ptr); \
29 while (entry && id != entry->id) \
30 entry = entry->next; \
31 (entry && id == entry->id ? entry->struct_member : NULL); \
34 const char *lookup_vendor(unsigned int id
)
36 return __do_lookup_inline(id
, vendor_id
, &oui
, vendor
);
39 void dissector_init_oui(void)
43 struct vendor_id
*ven
;
49 fp
= fopen("/etc/netsniff-ng/oui.conf", "r");
51 panic("No /etc/netsniff-ng/oui.conf found!\n");
53 memset(buff
, 0, sizeof(buff
));
54 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
55 buff
[sizeof(buff
) - 1] = 0;
57 ven
= xmalloc(sizeof(*ven
));
60 ptr
= getuint(ptr
, &ven
->id
);
62 ptr
= skipchar(ptr
, ',');
64 ptr
= strtrim_right(ptr
, '\n');
65 ptr
= strtrim_right(ptr
, ' ');
66 ven
->vendor
= xstrdup(ptr
);
68 pos
= insert_hash(ven
->id
, ven
, &oui
);
73 memset(buff
, 0, sizeof(buff
));
80 static int __dissector_cleanup_oui(void *ptr
)
82 struct vendor_id
*tmp
, *v
= ptr
;
85 while ((tmp
= v
->next
)) {
96 void dissector_cleanup_oui(void)
98 for_each_hash(&oui
, __dissector_cleanup_oui
);