2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * 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
)
30 v
= lookup_hash(id
, &oui
);
31 while (v
&& id
!= v
->id
)
34 return (v
&& id
== v
->id
? v
->vendor
: NULL
);
37 void dissector_init_oui(void)
47 fp
= fopen(PREFIX_STRING
"/etc/netsniff-ng/oui.conf", "r");
49 panic("No oui.conf found!\n");
51 memset(buff
, 0, sizeof(buff
));
53 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
54 buff
[sizeof(buff
) - 1] = 0;
57 v
= xmalloc(sizeof(*v
));
58 v
->id
= strtol(ptr
, &ptr
, 0);
60 if ((ptr
= strstr(buff
, ", ")))
62 ptr
= strtrim_right(ptr
, '\n');
63 ptr
= strtrim_right(ptr
, ' ');
65 v
->vendor
= xstrdup(ptr
);
68 pos
= insert_hash(v
->id
, v
, &oui
);
74 memset(buff
, 0, sizeof(buff
));
81 static int dissector_cleanup_oui_hash(void *ptr
)
83 struct vendor_id
*tmp
, *v
= ptr
;
88 while ((tmp
= v
->next
)) {
100 void dissector_cleanup_oui(void)
102 for_each_hash(&oui
, dissector_cleanup_oui_hash
);