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 const char *lookup_vendor(unsigned int id
)
26 struct vendor_id
*entry
= lookup_hash(id
, &oui
);
28 while (entry
&& id
!= entry
->id
)
31 return (entry
&& id
== entry
->id
? entry
->vendor
: NULL
);
34 void dissector_init_oui(void)
38 struct vendor_id
*ven
;
44 fp
= fopen("/etc/netsniff-ng/oui.conf", "r");
46 panic("No /etc/netsniff-ng/oui.conf found!\n");
48 memset(buff
, 0, sizeof(buff
));
49 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
50 buff
[sizeof(buff
) - 1] = 0;
52 ven
= xmalloc(sizeof(*ven
));
55 ptr
= getuint(ptr
, &ven
->id
);
57 ptr
= skipchar(ptr
, ',');
59 ptr
= strtrim_right(ptr
, '\n');
60 ptr
= strtrim_right(ptr
, ' ');
61 ven
->vendor
= xstrdup(ptr
);
63 pos
= insert_hash(ven
->id
, ven
, &oui
);
68 memset(buff
, 0, sizeof(buff
));
75 static int __dissector_cleanup_oui(void *ptr
)
77 struct vendor_id
*tmp
, *v
= ptr
;
80 while ((tmp
= v
->next
)) {
91 void dissector_cleanup_oui(void)
93 for_each_hash(&oui
, __dissector_cleanup_oui
);