From 39cd7dedca394c3b1bf38890e7a6185b75de8c04 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 14 Feb 2010 22:46:46 +0000 Subject: Version 0.4 and fixes. Outstanding commit from a while back. --- configure.in | 4 ++-- module/bsnmp-pcap.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/configure.in b/configure.in index fa42d4a..41e1934 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT(bsnmp-pcap, 0.3, stef@memberwebs.com) -AM_INIT_AUTOMAKE(bsnmp-pcap, 0.3) +AC_INIT(bsnmp-pcap, 0.4, stef@memberwebs.com) +AM_INIT_AUTOMAKE(bsnmp-pcap, 0.4) AC_CONFIG_SRCDIR([module/bsnmp-pcap.c]) AM_CONFIG_HEADER([config.h]) diff --git a/module/bsnmp-pcap.c b/module/bsnmp-pcap.c index 9a1aa45..f88ab16 100644 --- a/module/bsnmp-pcap.c +++ b/module/bsnmp-pcap.c @@ -80,11 +80,11 @@ struct monitor { uint32_t index; TAILQ_ENTRY(monitor) link; - u_char *descr; - u_char *device; + char *descr; + char *device; pcap_t *handle; void *watch; - u_char *filter; + char *filter; struct bpf_program filter_bpf; int filter_valid; @@ -175,11 +175,14 @@ static void monitor_io (int fd, void *data) { struct monitor* mon = (struct monitor*)data; + const char *error; int n_packets; n_packets = pcap_dispatch (mon->handle, -1, monitor_packet, (u_char*)mon); - if (n_packets < 0) - emsg ("couldn't capture packets in monitor: %s", pcap_geterr (mon->handle)); + if (n_packets < 0) { + error = pcap_geterr (mon->handle); + emsg ("couldn't capture packets in monitor: %s", error ? error : ""); + } } static void @@ -249,6 +252,7 @@ static void monitor_start (struct monitor *mon) { char errbuf[PCAP_ERRBUF_SIZE]; + const char *error; int fd; ASSERT (mon->device); @@ -261,13 +265,15 @@ monitor_start (struct monitor *mon) } if (pcap_compile (mon->handle, &mon->filter_bpf, mon->filter, 1, 0) < 0) { - emsg ("couldn't compile monitor expression: %s", pcap_geterr (mon->handle)); + error = pcap_geterr (mon->handle); + emsg ("couldn't compile monitor expression: %s", error ? error : ""); return; } mon->filter_valid = 1; if (pcap_setfilter (mon->handle, &mon->filter_bpf) < 0) { - emsg ("couldn't setup monitor expression: %s", pcap_geterr (mon->handle)); + error = pcap_geterr (mon->handle); + emsg ("couldn't setup monitor expression: %s", error ? error : ""); return; } @@ -278,7 +284,8 @@ monitor_start (struct monitor *mon) fd = pcap_get_selectable_fd (mon->handle); if (fd < 0) { - emsg ("couldn't get selectable monitor: %s", pcap_geterr (mon->handle)); + error = pcap_geterr (mon->handle); + emsg ("couldn't get selectable monitor: %s", error ? error : ""); return; } @@ -311,11 +318,11 @@ op_config (struct monitor *mon, struct snmp_context *ctx, value->v.integer = mon->index; return SNMP_ERR_NOERROR; case LEAF_pcapDescr: - return string_get (value, mon->descr, -1); + return string_get (value, (const u_char*)(mon->descr), -1); case LEAF_pcapDevice: - return string_get (value, mon->device, -1); + return string_get (value, (const u_char*)(mon->device), -1); case LEAF_pcapFilter: - return string_get (value, mon->filter, -1); + return string_get (value, (const u_char*)(mon->filter), -1); default: ASSERT (0); return SNMP_ERR_NOSUCHNAME; @@ -348,7 +355,7 @@ op_config (struct monitor *mon, struct snmp_context *ctx, case LEAF_pcapDescr: switch (op) { case SNMP_OP_SET: - return string_save (value, ctx, -1, &mon->descr); + return string_save (value, ctx, -1, (u_char**)(&mon->descr)); case SNMP_OP_ROLLBACK: return SNMP_ERR_NOERROR; case SNMP_OP_COMMIT: @@ -363,7 +370,7 @@ op_config (struct monitor *mon, struct snmp_context *ctx, case LEAF_pcapDevice: switch (op) { case SNMP_OP_SET: - return string_save (value, ctx, -1, &mon->device); + return string_save (value, ctx, -1, (u_char**)(&mon->device)); case SNMP_OP_ROLLBACK: return SNMP_ERR_NOERROR; case SNMP_OP_COMMIT: @@ -378,7 +385,7 @@ op_config (struct monitor *mon, struct snmp_context *ctx, case LEAF_pcapFilter: switch (op) { case SNMP_OP_SET: - r = string_save (value, ctx, -1, &mon->filter); + r = string_save (value, ctx, -1, (u_char**)(&mon->filter)); return r; case SNMP_OP_ROLLBACK: return SNMP_ERR_NOERROR; @@ -494,7 +501,6 @@ static int module_fini (void) { struct monitor *mon; -fprintf(stderr, "fini\n"); if (reg_index) or_unregister (reg_index); @@ -524,7 +530,7 @@ static void module_start (void) { struct monitor *mon; -fprintf(stderr, "start\n"); + reg_index = or_register (&oid_pcap, "The MIB for pcap data.", module); /* Start each monitor */ -- cgit v1.2.3