summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dissector_eth.c12
-rw-r--r--flowtop.c8
-rw-r--r--lookup.c48
-rw-r--r--lookup.h16
4 files changed, 43 insertions, 41 deletions
diff --git a/dissector_eth.c b/dissector_eth.c
index 60d8429..b2c44df 100644
--- a/dissector_eth.c
+++ b/dissector_eth.c
@@ -70,9 +70,9 @@ void dissector_init_ethernet(int fnttype)
dissector_init_oui();
- lookup_init_ports(PORTS_UDP);
- lookup_init_ports(PORTS_TCP);
- lookup_init_ports(PORTS_ETHER);
+ lookup_init(LT_PORTS_UDP);
+ lookup_init(LT_PORTS_TCP);
+ lookup_init(LT_ETHERTYPES);
}
void dissector_cleanup_ethernet(void)
@@ -80,9 +80,9 @@ void dissector_cleanup_ethernet(void)
free_hash(&eth_lay2);
free_hash(&eth_lay3);
- lookup_cleanup_ports(PORTS_ETHER);
- lookup_cleanup_ports(PORTS_TCP);
- lookup_cleanup_ports(PORTS_UDP);
+ lookup_cleanup(LT_ETHERTYPES);
+ lookup_cleanup(LT_PORTS_TCP);
+ lookup_cleanup(LT_PORTS_UDP);
dissector_cleanup_oui();
}
diff --git a/flowtop.c b/flowtop.c
index 41e80b7..cf0e478 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -1212,8 +1212,8 @@ static void presenter(void)
int skip_lines = 0;
WINDOW *screen;
- lookup_init_ports(PORTS_TCP);
- lookup_init_ports(PORTS_UDP);
+ lookup_init(LT_PORTS_TCP);
+ lookup_init(LT_PORTS_UDP);
screen = screen_init(false);
start_color();
@@ -1292,8 +1292,8 @@ static void presenter(void)
rcu_unregister_thread();
screen_end();
- lookup_cleanup_ports(PORTS_UDP);
- lookup_cleanup_ports(PORTS_TCP);
+ lookup_cleanup(LT_PORTS_UDP);
+ lookup_cleanup(LT_PORTS_TCP);
}
static int flow_event_cb(enum nf_conntrack_msg_type type,
diff --git a/lookup.c b/lookup.c
index 874a9b1..f903fe6 100644
--- a/lookup.c
+++ b/lookup.c
@@ -1,11 +1,13 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
- * Copyright 2014 Tobias Klauser
+ * Copyright 2014, 2015 Tobias Klauser
* Subject to the GPL, version 2.
*/
#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
#include <string.h>
#include "hash.h"
@@ -13,29 +15,29 @@
#include "lookup.h"
#include "xmalloc.h"
-static struct hash_table lookup_port_tables[PORTS_MAX];
+static struct hash_table lookup_port_tables[LT_MAX];
static const char * const lookup_port_files[] = {
- [PORTS_UDP] = ETCDIRE_STRING "/udp.conf",
- [PORTS_TCP] = ETCDIRE_STRING "/tcp.conf",
- [PORTS_ETHER] = ETCDIRE_STRING "/ether.conf",
+ [LT_PORTS_UDP] = ETCDIRE_STRING "/udp.conf",
+ [LT_PORTS_TCP] = ETCDIRE_STRING "/tcp.conf",
+ [LT_ETHERTYPES] = ETCDIRE_STRING "/ether.conf",
};
-struct port {
+struct lookup_entry {
unsigned int id;
- char *port;
- struct port *next;
+ char *str;
+ struct lookup_entry *next;
};
-void lookup_init_ports(enum ports which)
+void lookup_init(enum lookup_type which)
{
FILE *fp;
char buff[128], *ptr, *end;
const char *file;
struct hash_table *table;
- struct port *p;
+ struct lookup_entry *p;
void **pos;
- bug_on(which >= PORTS_MAX);
+ bug_on(which >= LT_MAX);
table = &lookup_port_tables[which];
file = lookup_port_files[which];
@@ -72,7 +74,7 @@ void lookup_init_ports(enum ports which)
ptr = strtrim_right(ptr, '\n');
ptr = strtrim_right(ptr, ' ');
- p->port = xstrdup(ptr);
+ p->str = xstrdup(ptr);
p->next = NULL;
pos = insert_hash(p->id, p, table);
@@ -89,55 +91,55 @@ void lookup_init_ports(enum ports which)
static int __lookup_cleanup_single(void *ptr)
{
- struct port *tmp, *p = ptr;
+ struct lookup_entry *tmp, *p = ptr;
if (!ptr)
return 0;
while ((tmp = p->next)) {
- xfree(p->port);
+ xfree(p->str);
xfree(p);
p = tmp;
}
- xfree(p->port);
+ xfree(p->str);
xfree(p);
return 0;
}
-void lookup_cleanup_ports(enum ports which)
+void lookup_cleanup(enum lookup_type which)
{
struct hash_table *table;
- bug_on(which >= PORTS_MAX);
+ bug_on(which >= LT_MAX);
table = &lookup_port_tables[which];
for_each_hash(table, __lookup_cleanup_single);
free_hash(table);
}
-#define __do_lookup_inline(id, struct_name, hash_ptr, struct_member) \
+#define __do_lookup_inline(id, hash_ptr) \
({ \
- struct struct_name *entry = lookup_hash(id, hash_ptr); \
+ struct lookup_entry *entry = lookup_hash(id, hash_ptr); \
\
while (entry && id != entry->id) \
entry = entry->next; \
\
- (entry && id == entry->id ? entry->struct_member : NULL); \
+ (entry && id == entry->id ? entry->str : NULL); \
})
char *lookup_ether_type(unsigned int id)
{
- return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_ETHER], port);
+ return __do_lookup_inline(id, &lookup_port_tables[LT_ETHERTYPES]);
}
char *lookup_port_udp(unsigned int id)
{
- return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_UDP], port);
+ return __do_lookup_inline(id, &lookup_port_tables[LT_PORTS_UDP]);
}
char *lookup_port_tcp(unsigned int id)
{
- return __do_lookup_inline(id, port, &lookup_port_tables[PORTS_TCP], port);
+ return __do_lookup_inline(id, &lookup_port_tables[LT_PORTS_TCP]);
}
diff --git a/lookup.h b/lookup.h
index 7cc2d31..50a4d86 100644
--- a/lookup.h
+++ b/lookup.h
@@ -1,22 +1,22 @@
/*
* netsniff-ng - the packet sniffing beast
* Copyright 2009, 2010 Daniel Borkmann.
- * Copyright 2014 Tobias Klauser
+ * Copyright 2014, 2015 Tobias Klauser
* Subject to the GPL, version 2.
*/
#ifndef LOOKUP_H
#define LOOKUP_H
-enum ports {
- PORTS_UDP,
- PORTS_TCP,
- PORTS_ETHER,
- PORTS_MAX,
+enum lookup_type {
+ LT_PORTS_UDP,
+ LT_PORTS_TCP,
+ LT_ETHERTYPES,
+ LT_MAX,
};
-extern void lookup_init_ports(enum ports which);
-extern void lookup_cleanup_ports(enum ports which);
+extern void lookup_init(enum lookup_type which);
+extern void lookup_cleanup(enum lookup_type which);
extern char *lookup_port_udp(unsigned int id);
extern char *lookup_port_tcp(unsigned int id);