2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009 - 2013 Daniel Borkmann.
5 * Subject to the GPL, version 2.
16 static struct hash_table oui
;
18 static bool initialized
= false;
23 struct vendor_id
*next
;
26 const char *lookup_vendor(unsigned int id
)
28 struct vendor_id
*entry
;
30 entry
= lookup_hash(id
, &oui
);
31 while (entry
&& id
!= entry
->id
)
34 return (entry
&& id
== entry
->id
?
35 entry
->vendor
: NULL
);
38 void dissector_init_oui(void)
48 fp
= fopen("/etc/netsniff-ng/oui.conf", "r");
50 panic("No oui.conf found!\n");
52 memset(buff
, 0, sizeof(buff
));
54 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
55 buff
[sizeof(buff
) - 1] = 0;
58 v
= xmalloc(sizeof(*v
));
59 v
->id
= strtol(ptr
, &ptr
, 0);
61 if ((ptr
= strstr(buff
, ", ")))
63 ptr
= strtrim_right(ptr
, '\n');
64 ptr
= strtrim_right(ptr
, ' ');
66 v
->vendor
= xstrdup(ptr
);
69 pos
= insert_hash(v
->id
, v
, &oui
);
75 memset(buff
, 0, sizeof(buff
));
82 static int dissector_cleanup_oui_hash(void *ptr
)
84 struct vendor_id
*tmp
, *v
= ptr
;
89 while ((tmp
= v
->next
)) {
101 void dissector_cleanup_oui(void)
103 for_each_hash(&oui
, dissector_cleanup_oui_hash
);