static void dissector_init_ether_types(void) { FILE *fp; char buff[512], *ptr; struct ether_type *et; void **pos; fp = fopen("/etc/netsniff-ng/ether.conf", "r"); if (!fp) panic("No /etc/netsniff-ng/ether.conf found!\n"); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; et = xmalloc(sizeof(*et)); ptr = buff; ptr = skips(ptr); ptr = getuint(ptr, &et->id); ptr = skips(ptr); ptr = skipchar(ptr, ','); ptr = skips(ptr); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); et->type = xstrdup(ptr); et->next = NULL; pos = insert_hash(et->id, et, ð_ether_types); if (pos) { et->next = *pos; *pos = et; } memset(buff, 0, sizeof(buff)); } fclose(fp); }
static void dissector_init_ports_tcp(void) { FILE *fp; char buff[512], *ptr; struct port_tcp *ptcp; void **pos; fp = fopen("/etc/netsniff-ng/tcp.conf", "r"); if (!fp) panic("No /etc/netsniff-ng/tcp.conf found!\n"); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; ptcp = xmalloc(sizeof(*ptcp)); ptr = buff; ptr = skips(ptr); ptr = getuint(ptr, &ptcp->id); ptr = skips(ptr); ptr = skipchar(ptr, ','); ptr = skips(ptr); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); ptcp->port = xstrdup(ptr); ptcp->next = NULL; pos = insert_hash(ptcp->id, ptcp, ð_ports_tcp); if (pos) { ptcp->next = *pos; *pos = ptcp; } memset(buff, 0, sizeof(buff)); } fclose(fp); }
static void dissector_init_oui(void) { FILE *fp; char buff[512], *ptr; struct vendor_id *ven; void **pos; fp = fopen("/etc/netsniff-ng/oui.conf", "r"); if (!fp) panic("No /etc/netsniff-ng/oui.conf found!\n"); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; ven = xmalloc(sizeof(*ven)); ptr = buff; ptr = skips(ptr); ptr = getuint(ptr, &ven->id); ptr = skips(ptr); ptr = skipchar(ptr, ','); ptr = skips(ptr); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); ven->vendor = xstrdup(ptr); ven->next = NULL; pos = insert_hash(ven->id, ven, ð_oui); if (pos) { ven->next = *pos; *pos = ven; } memset(buff, 0, sizeof(buff)); } fclose(fp); }
static void dissector_init_ports(enum ports which) { FILE *fp; char buff[128], *ptr, *file; struct hash_table *table; struct port *p; void **pos; switch (which) { case PORTS_UDP: file = "/etc/netsniff-ng/udp.conf"; table = ð_ports_udp; break; case PORTS_TCP: file = "/etc/netsniff-ng/tcp.conf"; table = ð_ports_tcp; break; case PORTS_ETHER: file = "/etc/netsniff-ng/ether.conf"; table = ð_ether_types; break; default: bug(); } fp = fopen(file, "r"); if (!fp) panic("No %s found!\n", file); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; ptr = buff; p = xmalloc(sizeof(*p)); p->id = strtol(ptr, &ptr, 0); if ((ptr = strstr(buff, ", "))) ptr += strlen(", "); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); p->port = xstrdup(ptr); p->next = NULL; pos = insert_hash(p->id, p, table); if (pos) { p->next = *pos; *pos = p; } memset(buff, 0, sizeof(buff)); } fclose(fp); }
void dissector_init_oui(void) { FILE *fp; char buff[128], *ptr, *end; struct vendor_id *v; void **pos; if (initialized) return; fp = fopen(ETCDIRE_STRING "/oui.conf", "r"); if (!fp) panic("No oui.conf found!\n"); memset(buff, 0, sizeof(buff)); while (fgets(buff, sizeof(buff), fp) != NULL) { buff[sizeof(buff) - 1] = 0; ptr = buff; v = xmalloc(sizeof(*v)); v->id = strtol(ptr, &end, 0); /* not a valid line, skip */ if (v->id == 0 && end == ptr) { xfree(v); continue; } ptr = strstr(buff, ", "); /* likewise */ if (!ptr) { xfree(v); continue; } ptr += strlen(", "); ptr = strtrim_right(ptr, '\n'); ptr = strtrim_right(ptr, ' '); v->vendor = xstrdup(ptr); v->next = NULL; pos = insert_hash(v->id, v, &oui); if (pos) { v->next = *pos; *pos = v; } memset(buff, 0, sizeof(buff)); } fclose(fp); initialized = true; }
char *strtrim(char *const input) { return strtrim_right((char*)strtrim_left(input)); }