diff options
author | Ali Abdulkadir <autostart.ini@gmail.com> | 2017-10-21 13:06:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-21 13:06:58 +0300 |
commit | 9307be5f1961c5f913d6ab6e3be22b97c4c337a8 (patch) | |
tree | 91c50033e20ae066f818d52610187fc9feef7cc9 | |
parent | d950121cdbaa5ad3177817bc63c69174ea34f2d3 (diff) | |
parent | 34505e5206e0fda856c016964c4fc1371f5372d8 (diff) |
Merge branch 'master' into man
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 59 | ||||
-rw-r--r-- | Makefile.in | 6 | ||||
-rwxr-xr-x | configure | 86 | ||||
-rw-r--r-- | configure.ac | 57 | ||||
-rw-r--r-- | optimize.c | 2 | ||||
-rw-r--r-- | pcap-dll.rc | 6 | ||||
-rw-r--r-- | pcap-rdmasniff.c | 25 | ||||
-rw-r--r-- | pcap-rpcap.c | 11 | ||||
-rw-r--r-- | pcap.c | 30 | ||||
-rw-r--r-- | pcap/compiler-tests.h | 64 | ||||
-rw-r--r-- | pcap/dlt.h | 9 | ||||
-rw-r--r-- | pcap/funcattrs.h | 26 | ||||
-rwxr-xr-x | rpcapd/daemon.c | 15 | ||||
-rwxr-xr-x | rpcapd/fileconf.c | 2 | ||||
-rwxr-xr-x | rpcapd/rpcapd.c | 2 | ||||
-rw-r--r-- | rpcapd/rpcapd.rc | 6 |
17 files changed, 296 insertions, 112 deletions
diff --git a/.travis.yml b/.travis.yml index b26875b9..f4e5d089 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ env: - secure: "SwNcek+I4lMVcnb5EGGmNm6ljWN6C/mnXzBr82a5rEQNKxAoJfdvvPpKIp0iEfg5j0PtYlcRHoIDyVZ/6QM/WEw0wrio9Z0cio9hkOS6kV8g2QouXfnoNtKJ5nNso7UD2GPJ9+M0GIR1GZ0Edvxr81sHlNAkpVKydYGBwCIMGyg=" # Coverity run condition (avoid matrix multiple runs), need customized # build script. Need an update if new matrix cases. - - coverity_scan_run_condition='"$TRAVIS_OS_NAME" = linux -a "$CC" = gcc' + - coverity_scan_run_condition='"$TRAVIS_OS_NAME" = linux -a "$CC" = gcc -a "$REMOTE" = enable -a "$CMAKE" = no' # Coverity script test mode (if true no uploading, avoid reaching the quota) # usual processing: false. - coverity_scan_script_test_mode=false diff --git a/CMakeLists.txt b/CMakeLists.txt index 2080c2ed..fc9a8ce4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,19 +13,24 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) project(pcap) -# -# Call the library "wpcap" on Windows, for backwards compatibility. -# +################################################################### +# Parameters +################################################################### + if(WIN32) - set(LIBRARY_NAME wpcap) + # + # On Windows, allow the library name to be overridden, for the + # benefit of projects that combine libpcap with their own + # kernel-mode code to support capturing. + # + set(LIBRARY_NAME pcap CACHE STRING "Library name") else() + # + # On UN*X, it's always been libpcap. + # set(LIBRARY_NAME pcap) endif() -################################################################### -# Parameters -################################################################### - option(INET6 "Enable IPv6" ON) if(WIN32) option(USE_STATIC_RT "Use static Runtime" ON) @@ -195,7 +200,7 @@ if(WIN32) # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL # 0 means unused. - set(PACKAGE_VERSION_DLL "${PACKAGE_VERSION_PREDLL},0") + set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0) endif(WIN32) set(PACKAGE_NAME "${LIBRARY_NAME}") @@ -618,6 +623,18 @@ else() # Check for a bunch of headers for various packet capture mechanisms. # check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H) + if(HAVE_NET_BPF_H) + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + check_symbol_exists(BIOCSETIF net/bpf.h BPF_H_DEFINES_BIOCSETIF) + endif(HAVE_NET_BPF_H) check_include_file(net/pfilt.h HAVE_NET_PFILT_H) check_include_file(net/enet.h HAVE_NET_ENET_H) check_include_file(net/nit.h HAVE_NET_NIT_H) @@ -626,13 +643,18 @@ else() check_include_file(net/raw.h HAVE_NET_RAW_H) check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H) - if(HAVE_NET_BPF_H) + if(BPF_H_DEFINES_BIOCSETIF) # # BPF. # Check this before DLPI, so that we pick BPF on # Solaris 11 and later. # set(PCAP_TYPE bpf) + elseif(HAVE_LINUX_SOCKET_H) + # + # No prizes for guessing this one. + # + set(PCAP_TYPE linux) elseif(HAVE_NET_PFILT_H) # # DEC OSF/1, Digital UNIX, Tru64 UNIX @@ -653,11 +675,6 @@ else() # Pre-SunOS 4.x non-STREAMS NIT. # set(PCAP_TYPE nit) - elseif(HAVE_LINUX_SOCKET_H) - # - # No prizes for guessing this one. - # - set(PCAP_TYPE linux) elseif(HAVE_NET_RAW_H) # # IRIX snoop. @@ -1214,18 +1231,10 @@ if(ENABLE_REMOTE) add_subdirectory(rpcapd) endif(ENABLE_REMOTE) -file(GLOB PROJECT_SOURCE_LIST_CORE_H +file(GLOB PROJECT_SOURCE_LIST_H *.h pcap/*.h ) -set(PROJECT_SOURCE_LIST_H ${PROJECT_SOURCE_LIST_H} ${PROJECT_SOURCE_LIST_CORE_H}) - -if(WIN32) - file(GLOB PROJECT_SOURCE_LIST_WIN32_H - Win32/Include/*.h - ) - set(PROJECT_SOURCE_LIST_H ${PROJECT_SOURCE_LIST_H} ${PROJECT_SOURCE_LIST_WIN32_H}) -endif(WIN32) # # Check and add warning options if we have a .devel file. @@ -1462,7 +1471,6 @@ if(BUILD_SHARED_LIBS) ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.c - ${PROJECT_SOURCE_LIST_H} ${PROJECT_EXTERNAL_OBJECT_LIST} ) add_dependencies(${LIBRARY_NAME} SerializeTarget) @@ -1472,7 +1480,6 @@ add_library(${LIBRARY_NAME}_static STATIC ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.c - ${PROJECT_SOURCE_LIST_H} ${PROJECT_EXTERNAL_OBJECT_LIST} ) add_dependencies(${LIBRARY_NAME}_static SerializeTarget) diff --git a/Makefile.in b/Makefile.in index 02bfe562..2901c5d9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -62,7 +62,7 @@ DYEXT = @DYEXT@ V_RPATH_OPT = @V_RPATH_OPT@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@ PROG=libpcap -RPCAPD=@RPCAPD@ +BUILD_RPCAPD=@BUILD_RPCAPD@ INSTALL_RPCAPD=@INSTALL_RPCAPD@ RPCAPD_LIBS=@RPCAPD_LIBS@ @@ -382,7 +382,7 @@ EXTRA_DIST = \ Win32/Prj/wpcap.vcxproj \ Win32/Prj/wpcap.vcxproj.filters -all: libpcap.a shared $(RPCAPD) pcap-config +all: libpcap.a shared $(BUILD_RPCAPD) pcap-config libpcap.a: $(OBJ) @rm -f $@ @@ -530,7 +530,7 @@ pcap-config: $(srcdir)/pcap-config.in ./config.status # # Remote pcap daemon. # -rpcapd: libpcap.a +build-rpcapd: libpcap.a cd rpcapd; $(MAKE) # @@ -639,7 +639,7 @@ USB_SRC PCAP_SUPPORT_USB RPCAPD_LIBS INSTALL_RPCAPD -RPCAPD +BUILD_RPCAPD MAN_USERMOD_SECTION MAN_MISC_INFO MAN_FILE_FORMATS @@ -5358,7 +5358,63 @@ else # Check for a bunch of headers for various packet # capture mechanisms. # - for ac_header in net/bpf.h net/pfilt.h net/enet.h + for ac_header in net/bpf.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "net/bpf.h" "ac_cv_header_net_bpf_h" "$ac_includes_default" +if test "x$ac_cv_header_net_bpf_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_NET_BPF_H 1 +_ACEOF + +fi + +done + + if test "$ac_cv_header_net_bpf_h" = yes; then + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if net/bpf.h defines BIOCSETIF" >&5 +$as_echo_n "checking if net/bpf.h defines BIOCSETIF... " >&6; } + if ${ac_cv_lbl_bpf_h_defines_biocsetif+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <sys/ioctl.h> +#ifdef HAVE_SYS_IOCCOM_H +#include <sys/ioccom.h> +#endif +#include <net/bpf.h> +#include <net/if.h> + +int +main () +{ +u_int i = BIOCSETIF; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_lbl_bpf_h_defines_biocsetif=yes +else + ac_cv_lbl_bpf_h_defines_biocsetif=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lbl_bpf_h_defines_biocsetif" >&5 +$as_echo "$ac_cv_lbl_bpf_h_defines_biocsetif" >&6; } + fi + for ac_header in net/pfilt.h net/enet.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -5398,7 +5454,7 @@ fi done - if test "$ac_cv_header_net_bpf_h" = yes; then + if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then # # BPF. # Check this before DLPI, so that we pick BPF on @@ -5417,6 +5473,17 @@ done VALGRINDTEST=valgrindtest ;; esac + elif test "$ac_cv_header_linux_socket_h" = yes; then + # + # No prizes for guessing this one. + # + V_PCAP=linux + + # + # XXX - this won't work with older kernels that have + # SOCK_PACKET sockets but not PF_PACKET sockets. + # + VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_pfilt_h" = yes; then # # DEC OSF/1, Digital UNIX, Tru64 UNIX @@ -5437,17 +5504,6 @@ done # Pre-SunOS 4.x non-STREAMS NIT. # V_PCAP=nit - elif test "$ac_cv_header_linux_socket_h" = yes; then - # - # No prizes for guessing this one. - # - V_PCAP=linux - - # - # XXX - this won't work with older kernels that have - # SOCK_PACKET sockets but not PF_PACKET sockets. - # - VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_raw_h" = yes; then # # IRIX snoop. @@ -7326,7 +7382,7 @@ done $as_echo "#define ENABLE_REMOTE /**/" >>confdefs.h SSRC="$SSRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c" - RPCAPD=rpcapd + BUILD_RPCAPD=build-rpcapd INSTALL_RPCAPD=install-rpcapd ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 diff --git a/configure.ac b/configure.ac index f8cdc516..5cb9f6fe 100644 --- a/configure.ac +++ b/configure.ac @@ -333,11 +333,38 @@ else # Check for a bunch of headers for various packet # capture mechanisms. # - AC_CHECK_HEADERS(net/bpf.h net/pfilt.h net/enet.h) + AC_CHECK_HEADERS(net/bpf.h) + if test "$ac_cv_header_net_bpf_h" = yes; then + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + AC_MSG_CHECKING(if net/bpf.h defines BIOCSETIF) + AC_CACHE_VAL(ac_cv_lbl_bpf_h_defines_biocsetif, + AC_TRY_COMPILE( +[ +#include <sys/ioctl.h> +#ifdef HAVE_SYS_IOCCOM_H +#include <sys/ioccom.h> +#endif +#include <net/bpf.h> +#include <net/if.h> +], + [u_int i = BIOCSETIF;], + ac_cv_lbl_bpf_h_defines_biocsetif=yes, + ac_cv_lbl_bpf_h_defines_biocsetif=no)) + AC_MSG_RESULT($ac_cv_lbl_bpf_h_defines_biocsetif) + fi + AC_CHECK_HEADERS(net/pfilt.h net/enet.h) AC_CHECK_HEADERS(net/nit.h sys/net/nit.h) AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h) - if test "$ac_cv_header_net_bpf_h" = yes; then + if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then # # BPF. # Check this before DLPI, so that we pick BPF on @@ -356,6 +383,17 @@ else VALGRINDTEST=valgrindtest ;; esac + elif test "$ac_cv_header_linux_socket_h" = yes; then + # + # No prizes for guessing this one. + # + V_PCAP=linux + + # + # XXX - this won't work with older kernels that have + # SOCK_PACKET sockets but not PF_PACKET sockets. + # + VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_pfilt_h" = yes; then # # DEC OSF/1, Digital UNIX, Tru64 UNIX @@ -376,17 +414,6 @@ else # Pre-SunOS 4.x non-STREAMS NIT. # V_PCAP=nit - elif test "$ac_cv_header_linux_socket_h" = yes; then - # - # No prizes for guessing this one. - # - V_PCAP=linux - - # - # XXX - this won't work with older kernels that have - # SOCK_PACKET sockets but not PF_PACKET sockets. - # - VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_raw_h" = yes; then # # IRIX snoop. @@ -1191,7 +1218,7 @@ yes) AC_MSG_RESULT(yes) AC_DEFINE(ENABLE_REMOTE,, [Define to 1 if remote packet capture is to be supported]) SSRC="$SSRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c" - RPCAPD=rpcapd + BUILD_RPCAPD=build-rpcapd INSTALL_RPCAPD=install-rpcapd ;; *) AC_MSG_RESULT(no) @@ -1559,7 +1586,7 @@ AC_SUBST(DYEXT) AC_SUBST(MAN_FILE_FORMATS) AC_SUBST(MAN_MISC_INFO) AC_SUBST(MAN_USERMOD_SECTION) -AC_SUBST(RPCAPD) +AC_SUBST(BUILD_RPCAPD) AC_SUBST(INSTALL_RPCAPD) AC_SUBST(RPCAPD_LIBS) @@ -60,7 +60,7 @@ int pcap_optimizer_debug; * * This is the same as the count of trailing zeroes in the word. */ -#if PCAP_IS_AT_LEAST_GNUC_VERSION(3, 4) +#if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) /* * GCC 3.4 and later; we have __builtin_ctz(). */ diff --git a/pcap-dll.rc b/pcap-dll.rc index 3f2c9eca..fc4f42b2 100644 --- a/pcap-dll.rc +++ b/pcap-dll.rc @@ -21,12 +21,12 @@ VALUE "CompanyName", "The TCPdump Group" VALUE "FileDescription", "System-Independent Interface for User-Level Packet Capture" VALUE "FileVersion", "PACKAGE_VERSION_DLL" - VALUE "InternalName", "PACKAGE_NAME" + VALUE "InternalName", PACKAGE_NAME VALUE "LegalCopyright", "Copyright (c) The TCPdump Group" VALUE "LegalTrademarks", "" VALUE "OriginalFilename", "wpcap.dll" - VALUE "ProductName", "PACKAGE_NAME" - VALUE "ProductVersion", "PACKAGE_VERSION" + VALUE "ProductName", PACKAGE_NAME + VALUE "ProductVersion", PACKAGE_VERSION END END BLOCK "VarFileInfo" diff --git a/pcap-rdmasniff.c b/pcap-rdmasniff.c index 6759ed83..512d8431 100644 --- a/pcap-rdmasniff.c +++ b/pcap-rdmasniff.c @@ -59,8 +59,21 @@ struct pcap_rdmasniff { u_char * oneshot_buffer; unsigned port_num; int cq_event; + u_int packets_recv; }; +static int +rdmasniff_stats(pcap_t *handle, struct pcap_stat *stat) +{ + struct pcap_rdmasniff *priv = handle->priv; + + stat->ps_recv = priv->packets_recv; + stat->ps_drop = 0; + stat->ps_ifdrop = 0; + + return 0; +} + static void rdmasniff_cleanup(pcap_t *handle) { @@ -109,8 +122,14 @@ rdmasniff_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u int count = 0; if (!priv->cq_event) { - if (ibv_get_cq_event(priv->channel, &ev_cq, &ev_ctx) < 0) { - return 0; + while (ibv_get_cq_event(priv->channel, &ev_cq, &ev_ctx) < 0) { + if (errno != EINTR) { + return PCAP_ERROR; + } + if (handle->break_loop) { + handle->break_loop = 0; + return PCAP_ERROR_BREAK; + } } ibv_ack_cq_events(priv->cq, 1); ibv_req_notify_cq(priv->cq, 0); @@ -139,6 +158,7 @@ rdmasniff_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u if (handle->fcode.bf_insns == NULL || bpf_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) { callback(user, &pkth, pktd); + ++priv->packets_recv; ++count; } @@ -285,6 +305,7 @@ rdmasniff_activate(pcap_t *handle) handle->offset = 0; handle->read_op = rdmasniff_read; + handle->stats_op = rdmasniff_stats; handle->cleanup_op = rdmasniff_cleanup; handle->setfilter_op = install_bpf_program; handle->setdirection_op = NULL; diff --git a/pcap-rpcap.c b/pcap-rpcap.c index 8ceb0b19..f3be8542 100644 --- a/pcap-rpcap.c +++ b/pcap-rpcap.c @@ -1918,8 +1918,6 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim int active = 0; /* '1' if we're in active mode */ /* socket-related variables */ - struct addrinfo hints; /* temp, needed to open a socket connection */ - struct addrinfo *addrinfo; /* temp, needed to open a socket connection */ SOCKET sockctrl; /* socket descriptor of the control connection */ /* RPCAP-related variables */ @@ -1976,8 +1974,6 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim return NULL; } - addrinfo = NULL; - /* * Warning: this call can be the first one called by the user. * For this reason, we have to initialize the WinSock support. @@ -2001,6 +1997,9 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim * We're not in active mode; let's try to open a new * control connection. */ + struct addrinfo hints; /* temp, needed to open a socket connection */ + struct addrinfo *addrinfo; /* temp, needed to open a socket connection */ + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -2032,7 +2031,6 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim } freeaddrinfo(addrinfo); - addrinfo = NULL; if (rpcap_sendauth(sockctrl, auth, errbuf) == -1) goto error; @@ -2130,9 +2128,6 @@ error: if (totread != ntohl(header.plen)) sock_discard(sockctrl, ntohl(header.plen) - totread, NULL, 0); - if (addrinfo) - freeaddrinfo(addrinfo); - if (!active) sock_close(sockctrl, NULL, 0); @@ -182,6 +182,12 @@ PCAP_API_DEF char pcap_version[] = PACKAGE_VERSION; static int pcap_not_initialized(pcap_t *pcap) { + if (pcap->activated) { + /* A module probably forgot to set the function pointer */ + (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), + "This operation isn't properly handled by that device"); + return (PCAP_ERROR); + } /* in case the caller doesn't check for PCAP_ERROR_NOT_ACTIVATED */ (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); @@ -193,6 +199,12 @@ pcap_not_initialized(pcap_t *pcap) static void * pcap_not_initialized_ptr(pcap_t *pcap) { + if (pcap->activated) { + /* A module probably forgot to set the function pointer */ + (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), + "This operation isn't properly handled by that device"); + return (NULL); + } (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); return (NULL); @@ -201,6 +213,12 @@ pcap_not_initialized_ptr(pcap_t *pcap) static HANDLE pcap_getevent_not_initialized(pcap_t *pcap) { + if (pcap->activated) { + /* A module probably forgot to set the function pointer */ + (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), + "This operation isn't properly handled by that device"); + return (INVALID_HANDLE_VALUE); + } (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); return (INVALID_HANDLE_VALUE); @@ -209,6 +227,12 @@ pcap_getevent_not_initialized(pcap_t *pcap) static u_int pcap_sendqueue_transmit_not_initialized(pcap_t *pcap, pcap_send_queue* queue, int sync) { + if (pcap->activated) { + /* A module probably forgot to set the function pointer */ + (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), + "This operation isn't properly handled by that device"); + return (0); + } (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); return (0); @@ -217,6 +241,12 @@ pcap_sendqueue_transmit_not_initialized(pcap_t *pcap, pcap_send_queue* queue, in static PAirpcapHandle pcap_get_airpcap_handle_not_initialized(pcap_t *pcap) { + if (pcap->activated) { + /* A module probably forgot to set the function pointer */ + (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), + "This operation isn't properly handled by that device"); + return (NULL); + } (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); return (NULL); diff --git a/pcap/compiler-tests.h b/pcap/compiler-tests.h index 205cd7a6..8876c67c 100644 --- a/pcap/compiler-tests.h +++ b/pcap/compiler-tests.h @@ -55,17 +55,41 @@ #endif /* + * Note that the C90 spec's "6.8.1 Conditional inclusion" and the + * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: + * + * Prior to evaluation, macro invocations in the list of preprocessing + * tokens that will become the controlling constant expression are + * replaced (except for those macro names modified by the defined unary + * operator), just as in normal text. If the token "defined" is + * generated as a result of this replacement process or use of the + * "defined" unary operator does not match one of the two specified + * forms prior to macro replacement, the behavior is undefined. + * + * so you shouldn't use defined() in a #define that's used in #if or + * #elif. Some versions of Clang, for example, will warn about this. + * + * Instead, we check whether the pre-defined macros for particular + * compilers are defined and, if not, define the "is this version XXX + * or a later version of this compiler" macros as 0. + */ + +/* * Check whether this is GCC major.minor or a later release, or some * compiler that claims to be "just like GCC" of that version or a * later release. */ + +#if ! defined(__GNUC__) +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 +#else #define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ - (defined(__GNUC__) && \ - (__GNUC__ > (major) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))) + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#endif /* - * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor + * Check whether this is Sun C/SunPro C/Oracle Studio major.minor * or a later release. * * The version number in __SUNPRO_C is encoded in hex BCD, with the @@ -81,26 +105,34 @@ * for a partial mapping, which we assume continues for later * 12.x product releases. */ + +#if ! defined(__SUNPRO_C) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 +#else #define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ (((minor) >= 10) ? \ (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ (((major) << 8) | ((minor) << 4))) -#define PCAP_IS_AT_LEAST_SUNC_VERSION(major, minor) \ - (defined(__SUNPRO_C) && \ - (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor)))) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ + (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) +#endif /* - * Check wehether this is IBM XL C major.minor or a later release. + * Check whether this is IBM XL C major.minor or a later release. * * The version number in __xlC__ has the major version in the * upper 8 bits and the minor version in the lower 8 bits. */ + +#if ! defined(__xlC__) +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 +#else #define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ - (defined(__xlC__) && __xlC__ >= (((major) << 8) | (minor))) + (__xlC__ >= (((major) << 8) | (minor))) +#endif /* - * Check wehether this is Sun C/SunPro C/Oracle Studio major.minor - * or a later release. + * Check whether this is HP aC++/HP C major.minor or a later release. * * The version number in __HP_aCC is encoded in zero-padded decimal BCD, * with the "A." stripped off, the uppermost two decimal digits being @@ -109,8 +141,12 @@ * (Strip off the A., remove the . between the major and minor version * number, and add two digits of patch.) */ -#define PCAP_IS_AT_LEAST_HP_C_VERSION(major, minor) \ - (defined(__HP_aCC) && \ - (__HP_aCC >= ((major)*10000 + (minor)*100))) + +#if ! defined(__HP_aCC) +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 +#else +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ + (__HP_aCC >= ((major)*10000 + (minor)*100)) +#endif #endif /* lib_pcap_funcattrs_h */ @@ -1342,6 +1342,13 @@ */ #define DLT_NORDIC_BLE 272 +/* + * Excentis DOCSIS 3.1 RF sniffer (XRA-31) + * per: bruno.verstuyft at excentis.com + */ +#define DLT_DOCSIS31_XRA31 273 + + /* * In case the code that includes this file (directly or indirectly) * has also included OS files that happen to define DLT_MATCHING_MAX, @@ -1352,7 +1359,7 @@ #ifdef DLT_MATCHING_MAX #undef DLT_MATCHING_MAX #endif -#define DLT_MATCHING_MAX 272 /* highest value in the "matching" range */ +#define DLT_MATCHING_MAX 273 /* highest value in the "matching" range */ /* * DLT and savefile link type values are split into a class and diff --git a/pcap/funcattrs.h b/pcap/funcattrs.h index a89f788d..cf923064 100644 --- a/pcap/funcattrs.h +++ b/pcap/funcattrs.h @@ -73,15 +73,15 @@ * shared library by default, so we might have to explicitly mark * functions as exported. */ - #if PCAP_IS_AT_LEAST_GNUC_VERSION(3, 4) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(12, 0) + #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0) /* * GCC 3.4 or later, or some compiler asserting compatibility with * GCC 3.4 or later, or XL C 13.0 or later, so we have * __attribute__((visibility()). */ #define PCAP_API_DEF __attribute__((visibility("default"))) - #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5, 5) + #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5) /* * Sun C 5.5 or later, so we have __global. * (Sun C 5.9 and later also have __attribute__((visibility()), @@ -111,10 +111,10 @@ * declaration, as the MSVC version has to go before the declaration.) */ #if __has_attribute(noreturn) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(2, 5) \ - || PCAP_IS_AT_LEAST_SUNC_VERSION(5, 9) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(10, 1) \ - || PCAP_IS_AT_LEAST_HP_C_VERSION(6, 10) + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* * Compiler with support for __attribute((noreturn)), or GCC 2.5 and * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 @@ -138,9 +138,9 @@ * string". */ #if __has_attribute(__format__) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(2, 3) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(10, 1) \ - || PCAP_IS_AT_LEAST_HP_C_VERSION(6, 10) + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1 * and later (do any earlier versions of XL C support this?), @@ -161,8 +161,8 @@ * (Thank you, Microsoft, for requiring the function name.) */ #if __has_attribute(deprecated) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(4, 5) \ - || PCAP_IS_AT_LEAST_SUNC_VERSION(5, 13) + || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) /* * Compiler that supports __has_attribute and __attribute__((deprecated)), * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. @@ -172,7 +172,7 @@ * recent enough to support __attribute__((deprecated(msg)))). */ #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg))) -#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3, 1) +#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1) /* * GCC 3.1 through 4.4. * diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c index ac51ecac..3d061983 100755 --- a/rpcapd/daemon.c +++ b/rpcapd/daemon.c @@ -561,25 +561,30 @@ int daemon_checkauth(SOCKET sockctrl, int nullAuthAllowed, char *errbuf) passwdlen = ntohs(auth.slen2); username = (char *) malloc (usernamelen + 1); - passwd = (char *) malloc (passwdlen + 1); - - if ((username == NULL) || (passwd == NULL)) + if (username == NULL) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc() failed: %s", pcap_strerror(errno)); retcode = -1; goto error; } - nread = sock_recv(sockctrl, username, usernamelen, SOCK_RECEIVEALL_YES, errbuf, PCAP_ERRBUF_SIZE); if (nread == -1) { free(username); - free(passwd); retcode = -1; goto error; } totread += nread; + + passwd = (char *) malloc (passwdlen + 1); + if (passwd == NULL) + { + snprintf(errbuf, PCAP_ERRBUF_SIZE, "malloc() failed: %s", pcap_strerror(errno)); + free(username); + retcode = -1; + goto error; + } nread = sock_recv(sockctrl, passwd, passwdlen, SOCK_RECEIVEALL_YES, errbuf, PCAP_ERRBUF_SIZE); if (nread == -1) diff --git a/rpcapd/fileconf.c b/rpcapd/fileconf.c index 824ddf8b..80fe645f 100755 --- a/rpcapd/fileconf.c +++ b/rpcapd/fileconf.c @@ -173,7 +173,7 @@ int fileconf_save(const char *savefile) fprintf(fp, "# Format: ActiveClient = <name or address>, <port | DEFAULT>\n\n"); - while ((activelist[i].address[0] != 0) && (i < MAX_ACTIVE_LIST)) + while ((i < MAX_ACTIVE_LIST) && (activelist[i].address[0] != 0)) { fprintf(fp, "ActiveClient = %s, %s\n", activelist[i].address, activelist[i].port); i++; diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index 1721c23f..fdb93325 100755 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -324,7 +324,7 @@ void main_startup(void) memset(errbuf, 0, sizeof(errbuf)); // Starts all the active threads - while ((activelist[i].address[0] != 0) && (i < MAX_ACTIVE_LIST)) + while ((i < MAX_ACTIVE_LIST) && (activelist[i].address[0] != 0)) { activelist[i].ai_family = mainhints.ai_family; diff --git a/rpcapd/rpcapd.rc b/rpcapd/rpcapd.rc index 809c6787..695c00b6 100644 --- a/rpcapd/rpcapd.rc +++ b/rpcapd/rpcapd.rc @@ -24,12 +24,12 @@ VALUE "CompanyName", "The TCPdump Group" VALUE "FileDescription", "Remote Packet Capture Daemon" VALUE "FileVersion", "PACKAGE_VERSION_DLL" - VALUE "InternalName", "PACKAGE_NAME" + VALUE "InternalName", PACKAGE_NAME VALUE "LegalCopyright", "Copyright (c) The TCPdump Group" VALUE "LegalTrademarks", "" VALUE "OriginalFilename", "rpcapd.exe" - VALUE "ProductName", "PACKAGE_NAME" - VALUE "ProductVersion", "PACKAGE_VERSION" + VALUE "ProductName", PACKAGE_NAME + VALUE "ProductVersion", PACKAGE_VERSION END END BLOCK "VarFileInfo" |