libpcap fixes for error handling and defines

remotes/origin/master-1.0.x
William Metcalf 15 years ago committed by Victor Julien
parent 4715c2f596
commit b5c19be29c

@ -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"

@ -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);
}

@ -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);
}

Loading…
Cancel
Save