aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
Diffstat (limited to 'epan')
-rw-r--r--epan/addr_resolv.c72
-rw-r--r--epan/range.c12
-rw-r--r--epan/range.h8
3 files changed, 51 insertions, 41 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c
index 9b0ca61a4a..f7e1911aa9 100644
--- a/epan/addr_resolv.c
+++ b/epan/addr_resolv.c
@@ -234,9 +234,10 @@ typedef struct _resolved_ipv6
static addrinfo_lists_t addrinfo_lists = { NULL, NULL};
-static gchar *cb_service;
-static port_type cb_proto = PT_NONE;
-
+struct cb_serv_data {
+ gchar *service;
+ port_type proto;
+};
static wmem_map_t *manuf_hashtable = NULL;
static wmem_map_t *wka_hashtable = NULL;
@@ -252,7 +253,7 @@ static gboolean new_resolved_objects = FALSE;
static GPtrArray* extra_hosts_files = NULL;
static hashether_t *add_eth_name(const guint8 *addr, const gchar *name);
-static void add_serv_port_cb(const guint32 port);
+static void add_serv_port_cb(const guint32 port, gpointer ptr);
/* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx#existing
@@ -475,18 +476,12 @@ add_service_name(port_type proto, const guint port, const char *service_name)
static void
parse_service_line (char *line)
{
- /*
- * See the services(4) or services(5) man page for services file format
- * (not available on all systems).
- */
-
gchar *cp;
gchar *service;
gchar *port;
port_type proto;
-
+ struct cb_serv_data cb_data;
range_t *port_rng = NULL;
- guint32 max_port = MAX_UDP_PORT;
if ((cp = strchr(line, '#')))
*cp = '\0';
@@ -504,48 +499,43 @@ parse_service_line (char *line)
if (strtok(cp, "/") == NULL)
return;
- if ((cp = strtok(NULL, "/")) == NULL)
- return;
-
- /* seems we got all interesting things from the file */
- if (strcmp(cp, "tcp") == 0) {
- max_port = MAX_TCP_PORT;
- proto = PT_TCP;
- }
- else if (strcmp(cp, "udp") == 0) {
- max_port = MAX_UDP_PORT;
- proto = PT_UDP;
- }
- else if (strcmp(cp, "sctp") == 0) {
- max_port = MAX_SCTP_PORT;
- proto = PT_SCTP;
- }
- else if (strcmp(cp, "dccp") == 0) {
- max_port = MAX_DCCP_PORT;
- proto = PT_DCCP;
- } else {
+ if (range_convert_str(NULL, &port_rng, port, G_MAXUINT16) != CVT_NO_ERROR) {
+ wmem_free (NULL, port_rng);
return;
}
- if (CVT_NO_ERROR != range_convert_str(NULL, &port_rng, port, max_port)) {
- /* some assertion here? */
- wmem_free (NULL, port_rng);
- return;
+ while ((cp = strtok(NULL, "/")) != NULL) {
+ if (strcmp(cp, "tcp") == 0) {
+ proto = PT_TCP;
+ }
+ else if (strcmp(cp, "udp") == 0) {
+ proto = PT_UDP;
+ }
+ else if (strcmp(cp, "sctp") == 0) {
+ proto = PT_SCTP;
+ }
+ else if (strcmp(cp, "dccp") == 0) {
+ proto = PT_DCCP;
+ }
+ else {
+ break;
+ }
+ cb_data.service = service;
+ cb_data.proto = proto;
+ range_foreach2(port_rng, add_serv_port_cb, &cb_data);
}
- cb_service = service;
- cb_proto = proto;
- range_foreach(port_rng, add_serv_port_cb);
wmem_free (NULL, port_rng);
- cb_proto = PT_NONE;
} /* parse_service_line */
static void
-add_serv_port_cb(const guint32 port)
+add_serv_port_cb(const guint32 port, gpointer ptr)
{
+ struct cb_serv_data *cb_data = (struct cb_serv_data *)ptr;
+
if ( port ) {
- add_service_name(cb_proto, port, cb_service);
+ add_service_name(cb_data->proto, port, cb_data->service);
}
}
diff --git a/epan/range.c b/epan/range.c
index 5bcfc60c95..1d4268967c 100644
--- a/epan/range.c
+++ b/epan/range.c
@@ -414,6 +414,18 @@ range_foreach(range_t *range, void (*callback)(guint32 val))
}
}
+void range_foreach2(range_t *range, void (*callback2)(guint32 val, gpointer ptr), gpointer ptr)
+{
+ guint32 i, j;
+
+ if (range && callback2) {
+ for (i=0; i < range->nranges; i++) {
+ for (j = range->ranges[i].low; j <= range->ranges[i].high; j++)
+ callback2(j, ptr);
+ }
+ }
+}
+
/* This function converts a range_t to a (wmem-allocated) string. */
char *
range_convert_range(wmem_allocator_t *scope, const range_t *range)
diff --git a/epan/range.h b/epan/range.h
index f090055240..791719ad59 100644
--- a/epan/range.h
+++ b/epan/range.h
@@ -137,6 +137,14 @@ WS_DLL_PUBLIC gboolean ranges_are_equal(range_t *a, range_t *b);
*/
WS_DLL_PUBLIC void range_foreach(range_t *range, void (*callback)(guint32 val));
+/** This function calls the provided callback function for each value in
+ * in the range. Takes an optional pointer argument.
+ * @param range the range
+ * @param callback the callback function
+ * @param ptr pointer passed to the callback
+ */
+WS_DLL_PUBLIC void range_foreach2(range_t *range, void (*callback2)(guint32 val, gpointer ptr), gpointer ptr);
+
/**
* This function converts a range_t to a (wmem_alloc()-allocated) string.
*/