From 4715c2f5968776076ed024f1c6fdd26d9ef21703 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 24 Jul 2009 09:31:30 +0200 Subject: [PATCH] Small pcap layout fixes, also made it a little bit more quiet. --- config.h.in | 6 ++++++ src/source-pcap.c | 19 ++++++++++--------- src/source-pcap.h | 6 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/config.h.in b/config.h.in index 40c32a495c..7d50134118 100644 --- a/config.h.in +++ b/config.h.in @@ -16,6 +16,9 @@ /* Define to 1 if you have the `nfnetlink' library (-lnfnetlink). */ #undef HAVE_LIBNFNETLINK +/* Define to 1 if you have the `pcap' library (-lpcap). */ +#undef HAVE_LIBPCAP + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H @@ -40,6 +43,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Major Version of Libpcap */ +#undef LIBPCAP_VERSION_MAJOR + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR diff --git a/src/source-pcap.c b/src/source-pcap.c index ccc65a5a36..bcb7aa246c 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -103,6 +103,7 @@ int ReceivePcap(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) { return 0; } + #if LIBPCAP_VERSION_MAJOR == 1 int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { if (initdata == NULL) { @@ -128,24 +129,23 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { exit(1); } - /* Snaplen, Promisc, and Timeout should be the same regardles of version - * Must be called before pcap_activate */ + /* 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); + //printf("ReceivePcapThreadInit: pcap_set_snaplen(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_snaplen_r); if (r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); 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); + //printf("ReceivePcapThreadInit: pcap_set_promisc(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_promisc_r); if (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); + //printf("ReceivePcapThreadInit: pcap_set_timeout(%p) returned %d\n", pcap_g.pcap_handle, pcap_set_timeout_r); if (r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); exit(1); @@ -153,14 +153,14 @@ 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); + //printf("ReceivePcapThreadInit: pcap_activate(%p) returned %d\n", pcap_g.pcap_handle, pcap_activate_r); if (r != 0) { printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(pcap_g.pcap_handle)); exit(1); } int datalink = pcap_datalink(pcap_g.pcap_handle); - printf("TmModuleReceivePcapFileRegister: datalink %d\n", datalink); + //printf("TmModuleReceivePcapFileRegister: datalink %d\n", datalink); switch(datalink) { case LINKTYPE_LINUX_SLL: pcap_g.Decoder = DecodeSll; @@ -180,7 +180,7 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { *data = (void *)ptv; return 0; } -#else +#else /* implied LIBPCAP_VERSION_MAJOR == 0 */ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { if (initdata == NULL) { printf("ReceivePcapThreadInit error: initdata == NULL\n"); @@ -226,7 +226,8 @@ int ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { *data = (void *)ptv; return 0; } -#endif +#endif /* LIBPCAP_VERSION_MAJOR */ + void ReceivePcapThreadExitStats(ThreadVars *tv, void *data) { PcapThreadVars *ptv = (PcapThreadVars *)data; diff --git a/src/source-pcap.h b/src/source-pcap.h index 0bc610c209..e12cb67666 100644 --- a/src/source-pcap.h +++ b/src/source-pcap.h @@ -7,9 +7,9 @@ void TmModuleReceivePcapRegister (void); void TmModuleDecodePcapRegister (void); /* XXX replace with user configurable options */ -#define LIBPCAP_SNAPLEN 1518 -#define LIBPCAP_COPYWAIT 500 -#define LIBPCAP_PROMISC 1 +#define LIBPCAP_SNAPLEN 1518 +#define LIBPCAP_COPYWAIT 500 +#define LIBPCAP_PROMISC 1 #endif /* __SOURCE_PCAP_H__ */