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)
46 fp
= fopen(PREFIX_STRING
"/etc/netsniff-ng/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
, &ptr
, 0);
59 if ((ptr
= strstr(buff
, ", ")))
61 ptr
= strtrim_right(ptr
, '\n');
62 ptr
= strtrim_right(ptr
, ' ');
64 v
->vendor
= xstrdup(ptr
);
67 pos
= insert_hash(v
->id
, v
, &oui
);
73 memset(buff
, 0, sizeof(buff
));
80 static int dissector_cleanup_oui_hash(void *ptr
)
82 struct vendor_id
*tmp
, *v
= ptr
;
87 while ((tmp
= v
->next
)) {
99 void dissector_cleanup_oui(void)
101 for_each_hash(&oui
, dissector_cleanup_oui_hash
);