2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
15 static struct hash_table oui
;
17 static bool initialized
= false;
22 struct vendor_id
*next
;
25 const char *lookup_vendor(unsigned int id
)
29 v
= lookup_hash(id
, &oui
);
30 while (v
&& id
!= v
->id
)
33 return (v
&& id
== v
->id
? v
->vendor
: NULL
);
36 void dissector_init_oui(void)
39 char buff
[128], *ptr
, *end
;
46 fp
= fopen(ETCDIRE_STRING
"/oui.conf", "r");
48 panic("No oui.conf found!\n");
50 memset(buff
, 0, sizeof(buff
));
52 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
53 buff
[sizeof(buff
) - 1] = 0;
56 v
= xmalloc(sizeof(*v
));
57 v
->id
= strtol(ptr
, &end
, 0);
58 /* not a valid line, skip */
59 if (v
->id
== 0 && end
== ptr
) {
64 ptr
= strstr(buff
, ", ");
72 ptr
= strtrim_right(ptr
, '\n');
73 ptr
= strtrim_right(ptr
, ' ');
75 v
->vendor
= xstrdup(ptr
);
78 pos
= insert_hash(v
->id
, v
, &oui
);
84 memset(buff
, 0, sizeof(buff
));
91 static int dissector_cleanup_oui_hash(void *ptr
)
93 struct vendor_id
*tmp
, *v
= ptr
;
98 while ((tmp
= v
->next
)) {
110 void dissector_cleanup_oui(void)
115 for_each_hash(&oui
, dissector_cleanup_oui_hash
);