From b5c19be29cecae3184c15513ada8f2fbecc02042 Mon Sep 17 00:00:00 2001 From: William Metcalf Date: Fri, 24 Jul 2009 10:08:31 -0500 Subject: [PATCH] libpcap fixes for error handling and defines --- configure.in | 5 ++--- src/source-pcap-file.c | 3 ++- src/source-pcap.c | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/configure.in b/configure.in index 0fc8296e1c..9c859650a9 100644 --- a/configure.in +++ b/configure.in @@ -151,10 +151,9 @@ fi LIBPCAPVTEST="" AC_CHECK_LIB(pcap, pcap_activate,, LPCAPVTEST="no") if test "$LPCAPVTEST" != "no"; then - AC_DEFINE(LIBPCAP_VERSION_MAJOR,[1],[Major Version of Libpcap]) - CFLAGS="${CFLAGS} `pcap-config --defines` `pcap-config --cflags`" + CFLAGS="${CFLAGS} `pcap-config --defines` `pcap-config --cflags` -DLIBPCAP_VERSION_MAJOR=1" else - AC_DEFINE(LIBPCAP_VERSION_MAJOR,[0],[Major Version of Libpcap]) + CFLAGS="${CFLAGS} -DLIBPCAP_VERSION_MAJOR=0" fi LIBS="${LIBS} -lpcap" diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index c57df307ef..ee65978f8d 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -142,8 +142,9 @@ int ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) { /* XXX create a general pcap setup function */ char errbuf[PCAP_ERRBUF_SIZE]; pcap_g.pcap_handle = pcap_open_offline((char *)initdata, errbuf); + /* Cannot use pcap_geterror with pcap_open_offline have to use errbuf */ if (pcap_g.pcap_handle == NULL) { - printf("error %s\n", pcap_geterr(pcap_g.pcap_handle)); + printf("error %s\n", errbuf); exit(1); } diff --git a/src/source-pcap.c b/src/source-pcap.c index bcb7aa246c..0f70c82c87 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -132,21 +132,21 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { /* set Snaplen, Promisc, and Timeout. Must be called before pcap_activate */ int pcap_set_snaplen_r = pcap_set_snaplen(pcap_g.pcap_handle,LIBPCAP_SNAPLEN); //printf("ReceivePcapThreadInit: pcap_set_snaplen(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_snaplen_r); - if (r != 0) { + if (pcap_set_snaplen_r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); - exit(1) + exit(1); } int pcap_set_promisc_r = pcap_set_promisc(pcap_g.pcap_handle,LIBPCAP_PROMISC); //printf("ReceivePcapThreadInit: pcap_set_promisc(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_promisc_r); - if (r != 0) { + if (pcap_set_promisc_r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); exit(1); } int pcap_set_timeout_r = pcap_set_timeout(pcap_g.pcap_handle,LIBPCAP_COPYWAIT); //printf("ReceivePcapThreadInit: pcap_set_timeout(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_timeout_r); - if (r != 0) { + if (pcap_set_timeout_r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); exit(1); } @@ -154,7 +154,7 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { /* activate the handle */ int pcap_activate_r = pcap_activate(pcap_g.pcap_handle); //printf("ReceivePcapThreadInit: pcap_activate(%p) returned %d\n", pcap_g.pcap_handle, pcap_activate_r); - if (r != 0) { + if (pcap_activate_r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); exit(1); } @@ -200,8 +200,9 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { /* XXX create a general pcap setup function */ char errbuf[PCAP_ERRBUF_SIZE]; pcap_g.pcap_handle = pcap_open_live((char *)initdata, LIBPCAP_SNAPLEN, LIBPCAP_PROMISC, LIBPCAP_COPYWAIT, errbuf); + /* Cannot use pcap_geterror with pcap_open_live have to use errbuf */ if (pcap_g.pcap_handle == NULL) { - printf("error %s\n", pcap_geterr(pcap_g.pcap_handle)); + printf("error %s\n", errbuf); exit(1); }