From 0c889d6f5cfdbf008a345fa3292ee468931ab49a Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 12 Mar 2020 13:16:24 -0700 Subject: Require at least libpcap 0.8/WinPcap 3.1. 2004 called, they want their libpcap/WinPcap back. RHEL 6 initially shipped with libpcap 1.0; even old Enterprise(TM) versions of OSes ship with something shinier than 0.7.x these days. This lets us get rid of a bunch of #ifdefs and workaround code for missing APIs. Change-Id: I862cb027418b0a0c0f45a26979acea82f93f833b Reviewed-on: https://code.wireshark.org/review/36383 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- caputils/capture-pcap-util-int.h | 2 - caputils/capture-pcap-util-unix.c | 256 ----------------------- caputils/capture-pcap-util.c | 107 ---------- caputils/capture-wpcap.c | 420 ++------------------------------------ cmake/modules/FindPCAP.cmake | 114 ++++++----- cmakeconfig.h.in | 34 --- dumpcap.c | 74 +------ tshark.c | 46 ++--- 8 files changed, 98 insertions(+), 955 deletions(-) diff --git a/caputils/capture-pcap-util-int.h b/caputils/capture-pcap-util-int.h index 2fcb5e3abe..789f96dfdf 100644 --- a/caputils/capture-pcap-util-int.h +++ b/caputils/capture-pcap-util-int.h @@ -14,13 +14,11 @@ extern if_info_t *if_info_new(const char *name, const char *description, gboolean loopback); extern void if_info_add_address(if_info_t *if_info, struct sockaddr *addr); -#ifdef HAVE_PCAP_FINDALLDEVS #ifdef HAVE_PCAP_REMOTE extern GList *get_interface_list_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, int *err, char **err_str); #endif /* HAVE_PCAP_REMOTE */ extern GList *get_interface_list_findalldevs(int *err, char **err_str); -#endif /* HAVE_PCAP_FINDALLDEVS */ #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION /* diff --git a/caputils/capture-pcap-util-unix.c b/caputils/capture-pcap-util-unix.c index d827319819..9ad2296fbc 100644 --- a/caputils/capture-pcap-util-unix.c +++ b/caputils/capture-pcap-util-unix.c @@ -22,38 +22,6 @@ #include #endif -#ifndef HAVE_PCAP_FINDALLDEVS - -#include -#include -#include -#include - -#ifdef HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - -/* - * Keep Digital UNIX happy when including . - */ -struct mbuf; -struct rtentry; -#include - -#ifdef HAVE_SYS_SOCKIO_H -# include -#endif - -#endif /* HAVE_PCAP_FINDALLDEVS */ - #ifdef HAVE_LIBCAP # include #endif @@ -93,231 +61,11 @@ get_remote_interface_list(const char *hostname, const char *port, } #endif -#ifdef HAVE_PCAP_FINDALLDEVS GList * get_interface_list(int *err, char **err_str) { return get_interface_list_findalldevs(err, err_str); } -#else /* HAVE_PCAP_FINDALLDEVS */ -struct search_user_data { - char *name; - if_info_t *if_info; -}; - -static void -search_for_if_cb(gpointer data, gpointer user_data) -{ - struct search_user_data *search_user_data = (struct search_user_data*)user_data; - if_info_t *if_info = (if_info_t *)data; - - if (strcmp(if_info->name, search_user_data->name) == 0) - search_user_data->if_info = if_info; -} - -GList * -get_interface_list(cap_device_open_err *err, char **err_str) -{ - GList *il = NULL; - gint nonloopback_pos = 0; - struct ifreq *ifr, *last; - struct ifconf ifc; - struct ifreq ifrflags; - int sock = socket(AF_INET, SOCK_DGRAM, 0); - struct search_user_data user_data; - pcap_t *pch; - int len, lastlen; - char *buf; - if_info_t *if_info; - char errbuf[PCAP_ERRBUF_SIZE]; - gboolean loopback; - - if (sock < 0) { - *err = CANT_GET_INTERFACE_LIST; - if (err_str != NULL) { - *err_str = g_strdup_printf( - "Can't get list of interfaces: error opening socket: %s", - g_strerror(errno)); - } - return NULL; - } - - /* - * This code came from: W. Richard Stevens: "UNIX Network Programming", - * Networking APIs: Sockets and XTI, Vol 1, page 434. - */ - lastlen = 0; - len = 100 * sizeof(struct ifreq); - for ( ; ; ) { - buf = (char *)g_malloc0(len); - ifc.ifc_len = len; - ifc.ifc_buf = buf; - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { - if (errno != EINVAL || lastlen != 0) { - if (err_str != NULL) { - *err_str = g_strdup_printf( - "Can't get list of interfaces: SIOCGIFCONF ioctl error: %s", - g_strerror(errno)); - } - goto fail; - } - } else { - if ((unsigned int) ifc.ifc_len < sizeof(struct ifreq)) { - if (err_str != NULL) { - *err_str = g_strdup( - "Can't get list of interfaces: SIOCGIFCONF ioctl gave too small return buffer"); - } - goto fail; - } - if (ifc.ifc_len == lastlen) - break; /* success, len has not changed */ - lastlen = ifc.ifc_len; - } - len += 10 * sizeof(struct ifreq); /* increment */ - g_free(buf); - } - ifr = (struct ifreq *) ifc.ifc_req; - last = (struct ifreq *) ((char *) ifr + ifc.ifc_len); - while (ifr < last) { - /* - * Skip entries that begin with "dummy", or that include - * a ":" (the latter are Solaris virtuals). - */ - if (strncmp(ifr->ifr_name, "dummy", 5) == 0 || - strchr(ifr->ifr_name, ':') != NULL) - goto next; - - /* - * If we already have this interface name on the list, - * don't add it, but, if we don't already have an IP - * address for it, add that address (SIOCGIFCONF returns, - * at least on BSD-flavored systems, one entry per - * interface *address*; if an interface has multiple - * addresses, we get multiple entries for it). - */ - user_data.name = ifr->ifr_name; - user_data.if_info = NULL; - g_list_foreach(il, search_for_if_cb, &user_data); - if (user_data.if_info != NULL) { - if_info_add_address(user_data.if_info, &ifr->ifr_addr); - if (user_data.if_info->addrs) { - g_slist_reverse(user_data.if_info->addrs); - } - goto next; - } - - /* - * Get the interface flags. - */ - memset(&ifrflags, 0, sizeof ifrflags); - g_strlcpy(ifrflags.ifr_name, ifr->ifr_name, - sizeof ifrflags.ifr_name); - if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifrflags) < 0) { - if (errno == ENXIO) - goto next; - if (err_str != NULL) { - *err_str = g_strdup_printf( - "Can't get list of interfaces: SIOCGIFFLAGS error getting flags for interface %s: %s", - ifr->ifr_name, g_strerror(errno)); - } - goto fail; - } - - /* - * Skip interfaces that aren't up. - */ - if (!(ifrflags.ifr_flags & IFF_UP)) - goto next; - - /* - * Skip interfaces that we can't open with "libpcap". - * Open with the minimum packet size - it appears that the - * IRIX SIOCSNOOPLEN "ioctl" may fail if the capture length - * supplied is too large, rather than just truncating it. - */ - pch = pcap_open_live(ifr->ifr_name, MIN_PACKET_SIZE, 0, 0, - errbuf); - if (pch == NULL) - goto next; - pcap_close(pch); - - /* - * If it's a loopback interface, add it at the end of the - * list, otherwise add it after the last non-loopback - * interface, so all loopback interfaces go at the end - we - * don't want a loopback interface to be the default capture - * device unless there are no non-loopback devices. - */ - loopback = ((ifrflags.ifr_flags & IFF_LOOPBACK) || - strncmp(ifr->ifr_name, "lo", 2) == 0); - if_info = if_info_new(ifr->ifr_name, NULL, loopback); - if_info_add_address(if_info, &ifr->ifr_addr); - if (if_info->addrs) { - g_slist_reverse(if_info->addrs); - } - if (loopback) - il = g_list_append(il, if_info); - else { - il = g_list_insert(il, if_info, nonloopback_pos); - /* - * Insert the next non-loopback interface after this - * one. - */ - nonloopback_pos++; - } - - next: -#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - ifr = (struct ifreq *) ((char *) ifr + - (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_addr) ? - ifr->ifr_addr.sa_len : sizeof(ifr->ifr_addr)) + - IFNAMSIZ); -#else - ifr = (struct ifreq *) ((char *) ifr + sizeof(struct ifreq)); -#endif - } - -#ifdef linux - /* - * OK, maybe we have support for the "any" device, to do a cooked - * capture on all interfaces at once. - * Try opening it and, if that succeeds, add it to the end of - * the list of interfaces. - */ - pch = pcap_open_live("any", MIN_PACKET_SIZE, 0, 0, errbuf); - if (pch != NULL) { - /* - * It worked; we can use the "any" device. - */ - if_info = if_info_new("any", - "Pseudo-device that captures on all interfaces", FALSE); - il = g_list_insert(il, if_info, -1); - pcap_close(pch); - } -#endif - - g_free(ifc.ifc_buf); - close(sock); - - if (il == NULL) { - /* - * No interfaces found. - */ - *err = 0; - if (err_str != NULL) - *err_str = NULL; - } - return il; - -fail: - if (il != NULL) - free_interface_list(il); - g_free(ifc.ifc_buf); - close(sock); - *err = CANT_GET_INTERFACE_LIST; - return NULL; -} -#endif /* HAVE_PCAP_FINDALLDEVS */ /* * Get an error message string for a CANT_GET_INTERFACE_LIST error from @@ -526,11 +274,7 @@ void get_runtime_caplibs_version(GString *str) { g_string_append_printf(str, "with "); -#ifdef HAVE_PCAP_LIB_VERSION g_string_append(str, pcap_lib_version()); -#else - g_string_append(str, "libpcap (version unknown)"); -#endif } #else /* HAVE_LIBPCAP */ diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c index d0b55c9ff7..6fb1eb4dd5 100644 --- a/caputils/capture-pcap-util.c +++ b/caputils/capture-pcap-util.c @@ -570,7 +570,6 @@ if_info_add_address(if_info_t *if_info, struct sockaddr *addr) } } -#ifdef HAVE_PCAP_FINDALLDEVS /* * Get all IP address information for the given interface. */ @@ -669,7 +668,6 @@ get_interface_list_findalldevs(int *err, char **err_str) return il; } -#endif /* HAVE_PCAP_FINDALLDEVS */ static void free_if_cb(gpointer data, gpointer user_data _U_) @@ -684,95 +682,6 @@ free_interface_list(GList *if_list) g_list_free(if_list); } -#if !defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) -struct dlt_choice { - const char *name; - const char *description; - int dlt; -}; - -#define DLT_CHOICE(code, description) { #code, description, code } -#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } - -static struct dlt_choice dlt_choices[] = { - DLT_CHOICE(DLT_NULL, "BSD loopback"), - DLT_CHOICE(DLT_EN10MB, "Ethernet"), - DLT_CHOICE(DLT_IEEE802, "Token ring"), - DLT_CHOICE(DLT_ARCNET, "ARCNET"), - DLT_CHOICE(DLT_SLIP, "SLIP"), - DLT_CHOICE(DLT_PPP, "PPP"), - DLT_CHOICE(DLT_FDDI, "FDDI"), - DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), - DLT_CHOICE(DLT_RAW, "Raw IP"), - DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), - DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), - DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), - DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), - DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), - DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), - DLT_CHOICE(DLT_IEEE802_11, "802.11"), - DLT_CHOICE(DLT_FRELAY, "Frame Relay"), - DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), - DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), - DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), - DLT_CHOICE(DLT_LTALK, "Localtalk"), - DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), - DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), - DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), - DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), - DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus BSD radio information header"), - DLT_CHOICE(DLT_APPLE_IP_OVER_IEEE1394, "Apple IP-over-IEEE 1394"), - DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), - DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), - DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS, "802.11 plus AVS radio information header"), - DLT_CHOICE_SENTINEL -}; - -#if !defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) -static int -pcap_datalink_name_to_val(const char *name) -{ - int i; - - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, - name) == 0) - return (dlt_choices[i].dlt); - } - return (-1); -} -#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) */ - -#if !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) -static const char * -pcap_datalink_val_to_name(int dlt) -{ - int i; - - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (dlt_choices[i].dlt == dlt) - return (dlt_choices[i].name + sizeof("DLT_") - 1); - } - return (NULL); -} -#endif /* defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) */ - -#if !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) -const char * -pcap_datalink_val_to_description(int dlt) -{ - int i; - - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (dlt_choices[i].dlt == dlt) - return (dlt_choices[i].description); - } - return (NULL); -} -#endif /* defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) */ - -#endif /* !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) */ - static void free_linktype_cb(gpointer data, gpointer user_data _U_) { @@ -953,17 +862,9 @@ set_pcap_datalink(pcap_t *pcap_h, int datalink, char *name, if (datalink == -1) return TRUE; /* just use the default */ -#ifdef HAVE_PCAP_SET_DATALINK if (pcap_set_datalink(pcap_h, datalink) == 0) return TRUE; /* no error */ set_datalink_err_str = pcap_geterr(pcap_h); -#else - /* Let them set it to the type it is; reject any other request. */ - if (get_pcap_datalink(pcap_h, name) == datalink) - return TRUE; /* no error */ - set_datalink_err_str = - "That DLT isn't one of the DLTs supported by this device"; -#endif g_snprintf(errmsg, (gulong) errmsg_len, "Unable to set data link type on interface '%s' (%s).", name, set_datalink_err_str); /* @@ -1002,14 +903,11 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts, { GList *data_link_types; int deflt; -#ifdef HAVE_PCAP_LIST_DATALINKS int *linktypes; int i, nlt; -#endif data_link_info_t *data_link_info; deflt = get_pcap_datalink(pch, interface_opts->name); -#ifdef HAVE_PCAP_LIST_DATALINKS nlt = pcap_list_datalinks(pch, &linktypes); if (nlt < 0) { /* @@ -1082,11 +980,6 @@ get_data_link_types(pcap_t *pch, interface_options *interface_opts, xx_free(linktypes); #endif /* _WIN32 */ #endif /* HAVE_PCAP_FREE_DATALINKS */ -#else /* HAVE_PCAP_LIST_DATALINKS */ - - data_link_info = create_data_link_info(deflt); - data_link_types = g_list_append(data_link_types, data_link_info); -#endif /* HAVE_PCAP_LIST_DATALINKS */ *err_str = NULL; return data_link_types; diff --git a/caputils/capture-wpcap.c b/caputils/capture-wpcap.c index 5a81bdb5ce..461637fb2f 100644 --- a/caputils/capture-wpcap.c +++ b/caputils/capture-wpcap.c @@ -62,26 +62,14 @@ static int (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *, char *); static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *); static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *); -#ifdef HAVE_PCAP_OPEN_DEAD static pcap_t* (*p_pcap_open_dead) (int, int); -#endif static void (*p_pcap_freecode) (struct bpf_program *); -#ifdef HAVE_PCAP_FINDALLDEVS static int (*p_pcap_findalldevs) (pcap_if_t **, char *); static void (*p_pcap_freealldevs) (pcap_if_t *); -#endif -#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL static int (*p_pcap_datalink_name_to_val) (const char *); -#endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME static const char *(*p_pcap_datalink_val_to_name) (int); -#endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION static const char *(*p_pcap_datalink_val_to_description) (int); -#endif -#ifdef HAVE_PCAP_BREAKLOOP static void (*p_pcap_breakloop) (pcap_t *); -#endif static const char *(*p_pcap_lib_version) (void); static int (*p_pcap_setbuff) (pcap_t *, int dim); static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data); @@ -97,21 +85,14 @@ static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *, static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *); #endif -#ifdef HAVE_PCAP_LIST_DATALINKS static int (*p_pcap_list_datalinks)(pcap_t *, int **); -#endif - -#ifdef HAVE_PCAP_SET_DATALINK static int (*p_pcap_set_datalink)(pcap_t *, int); -#endif #ifdef HAVE_PCAP_FREE_DATALINKS static int (*p_pcap_free_datalinks)(int *); #endif -#ifdef HAVE_BPF_IMAGE static char *(*p_bpf_image)(const struct bpf_insn *, int); -#endif #ifdef HAVE_PCAP_CREATE static pcap_t *(*p_pcap_create)(const char *, char *); @@ -156,50 +137,27 @@ load_wpcap(void) SYM(pcap_createsrcstr, FALSE), #endif SYM(pcap_open_live, FALSE), -#ifdef HAVE_PCAP_OPEN_DEAD SYM(pcap_open_dead, FALSE), -#endif #ifdef HAVE_PCAP_SETSAMPLING SYM(pcap_setsampling, TRUE), #endif SYM(pcap_loop, FALSE), - SYM(pcap_freecode, TRUE), -#ifdef HAVE_PCAP_FINDALLDEVS - SYM(pcap_findalldevs, TRUE), - SYM(pcap_freealldevs, TRUE), -#endif -#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL - SYM(pcap_datalink_name_to_val, TRUE), -#endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME - SYM(pcap_datalink_val_to_name, TRUE), -#endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION - SYM(pcap_datalink_val_to_description, TRUE), -#endif -#ifdef HAVE_PCAP_BREAKLOOP - /* - * We don't try to work around the lack of this at - * run time; it's present in WinPcap 3.1, which is - * the version we build with and ship with. - */ + SYM(pcap_freecode, FALSE), + SYM(pcap_findalldevs, FALSE), + SYM(pcap_freealldevs, FALSE), + SYM(pcap_datalink_name_to_val, FALSE), + SYM(pcap_datalink_val_to_name, FALSE), + SYM(pcap_datalink_val_to_description, FALSE), SYM(pcap_breakloop, FALSE), -#endif - SYM(pcap_lib_version, TRUE), + SYM(pcap_lib_version, FALSE), SYM(pcap_setbuff, TRUE), SYM(pcap_next_ex, TRUE), -#ifdef HAVE_PCAP_LIST_DATALINKS SYM(pcap_list_datalinks, FALSE), -#endif -#ifdef HAVE_PCAP_SET_DATALINK SYM(pcap_set_datalink, FALSE), -#endif #ifdef HAVE_PCAP_FREE_DATALINKS SYM(pcap_free_datalinks, TRUE), #endif -#ifdef HAVE_BPF_IMAGE SYM(bpf_image, FALSE), -#endif #ifdef HAVE_PCAP_CREATE SYM(pcap_create, TRUE), SYM(pcap_set_snaplen, TRUE), @@ -351,14 +309,12 @@ pcap_datalink(pcap_t *a) return p_pcap_datalink(a); } -#ifdef HAVE_PCAP_SET_DATALINK int pcap_set_datalink(pcap_t *p, int dlt) { g_assert(has_wpcap); return p_pcap_set_datalink(p, dlt); } -#endif int pcap_setfilter(pcap_t *a, struct bpf_program *b) @@ -420,7 +376,6 @@ pcap_open_live(const char *a, int b, int c, int d, char *errbuf) return p; } -#ifdef HAVE_PCAP_OPEN_DEAD pcap_t* pcap_open_dead(int a, int b) { @@ -429,9 +384,7 @@ pcap_open_dead(int a, int b) } return p_pcap_open_dead(a, b); } -#endif -#ifdef HAVE_BPF_IMAGE char * bpf_image(const struct bpf_insn *a, int b) { @@ -440,7 +393,6 @@ bpf_image(const struct bpf_insn *a, int b) } return p_bpf_image(a, b); } -#endif #ifdef HAVE_PCAP_REMOTE pcap_t* @@ -506,12 +458,9 @@ void pcap_freecode(struct bpf_program *a) { g_assert(has_wpcap); - if(p_pcap_freecode) { - p_pcap_freecode(a); - } + p_pcap_freecode(a); } -#ifdef HAVE_PCAP_FINDALLDEVS int pcap_findalldevs(pcap_if_t **a, char *errbuf) { @@ -529,7 +478,6 @@ pcap_freealldevs(pcap_if_t *a) g_assert(has_wpcap && p_pcap_freealldevs != NULL); p_pcap_freealldevs(a); } -#endif #ifdef HAVE_PCAP_CREATE pcap_t * @@ -612,137 +560,19 @@ pcap_statustostr(int a) } #endif -#if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) -/* - * Table of DLT_ types, names, and descriptions, for use if the version - * of WinPcap we have installed lacks "pcap_datalink_name_to_val()" - * or "pcap_datalink_val_to_name()". - */ -struct dlt_choice { - const char *name; - const char *description; - int dlt; -}; - -#define DLT_CHOICE(code, description) { #code, description, code } -#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } - -static struct dlt_choice dlt_choices[] = { - DLT_CHOICE(DLT_NULL, "BSD loopback"), - DLT_CHOICE(DLT_EN10MB, "Ethernet"), - DLT_CHOICE(DLT_IEEE802, "Token ring"), - DLT_CHOICE(DLT_ARCNET, "ARCNET"), - DLT_CHOICE(DLT_SLIP, "SLIP"), - DLT_CHOICE(DLT_PPP, "PPP"), - DLT_CHOICE(DLT_FDDI, "FDDI"), - DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), - DLT_CHOICE(DLT_RAW, "Raw IP"), -#ifdef DLT_SLIP_BSDOS - DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), -#endif -#ifdef DLT_PPP_BSDOS - DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), -#endif -#ifdef DLT_ATM_CLIP - DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), -#endif -#ifdef DLT_PPP_SERIAL - DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), -#endif -#ifdef DLT_PPP_ETHER - DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), -#endif -#ifdef DLT_C_HDLC - DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), -#endif -#ifdef DLT_IEEE802_11 - DLT_CHOICE(DLT_IEEE802_11, "802.11"), -#endif -#ifdef DLT_FRELAY - DLT_CHOICE(DLT_FRELAY, "Frame Relay"), -#endif -#ifdef DLT_LOOP - DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), -#endif -#ifdef DLT_ENC - DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), -#endif -#ifdef DLT_LINUX_SLL - DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), -#endif -#ifdef DLT_LTALK - DLT_CHOICE(DLT_LTALK, "Localtalk"), -#endif -#ifdef DLT_PFLOG - DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), -#endif -#ifdef DLT_PRISM_HEADER - DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), -#endif -#ifdef DLT_IP_OVER_FC - DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), -#endif -#ifdef DLT_SUNATM - DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), -#endif -#ifdef DLT_IEEE802_11_RADIO - DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), -#endif -#ifdef DLT_ARCNET_LINUX - DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), -#endif -#ifdef DLT_LINUX_IRDA - DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), -#endif -#ifdef DLT_LINUX_LAPD - DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"), -#endif -#ifdef DLT_LANE8023 - DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"), -#endif -#ifdef DLT_CIP - DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), -#endif -#ifdef DLT_HDLC - DLT_CHOICE(DLT_HDLC, "Cisco HDLC"), -#endif -#ifdef DLT_PPI - DLT_CHOICE(DLT_PPI, "Per-Packet Information"), -#endif - DLT_CHOICE_SENTINEL -}; -#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */ - -#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL int pcap_datalink_name_to_val(const char *name) { - int i; - - if (has_wpcap && (p_pcap_datalink_name_to_val != NULL)) - return p_pcap_datalink_name_to_val(name); - else { - /* - * We don't have it in WinPcap; do it ourselves. - */ - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, - name) == 0) - return dlt_choices[i].dlt; - } - return -1; - } + g_assert(has_wpcap); + return p_pcap_datalink_name_to_val(name); } -#endif -#ifdef HAVE_PCAP_LIST_DATALINKS int pcap_list_datalinks(pcap_t *p, int **ddlt) { g_assert(has_wpcap); return p_pcap_list_datalinks(p, ddlt); } -#endif #ifdef HAVE_PCAP_FREE_DATALINKS void @@ -763,54 +593,24 @@ pcap_free_datalinks(int *ddlt) } #endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME const char * pcap_datalink_val_to_name(int dlt) { - int i; - - if (has_wpcap && (p_pcap_datalink_val_to_name != NULL)) - return p_pcap_datalink_val_to_name(dlt); - else { - /* - * We don't have it in WinPcap; do it ourselves. - */ - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (dlt_choices[i].dlt == dlt) - return dlt_choices[i].name + sizeof("DLT_") - 1; - } - return NULL; - } + g_assert(has_wpcap); + return p_pcap_datalink_val_to_name(dlt); } -#endif -#ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION const char * pcap_datalink_val_to_description(int dlt) { - int i; - - if (has_wpcap && (p_pcap_datalink_val_to_description != NULL)) - return p_pcap_datalink_val_to_description(dlt); - else { - /* - * We don't have it in WinPcap; do it ourselves. - */ - for (i = 0; dlt_choices[i].name != NULL; i++) { - if (dlt_choices[i].dlt == dlt) - return (dlt_choices[i].description); - } - return NULL; - } + g_assert(has_wpcap); + return p_pcap_datalink_val_to_description(dlt); } -#endif -#ifdef HAVE_PCAP_BREAKLOOP void pcap_breakloop(pcap_t *a) { p_pcap_breakloop(a); } -#endif /* setbuff is win32 specific! */ int pcap_setbuff(pcap_t *a, int b) @@ -865,14 +665,6 @@ get_remote_interface_list(const char *hostname, const char *port, GList * get_interface_list(int *err, char **err_str) { - GList *il = NULL; - wchar_t *names; - char *win95names; - char ascii_name[MAX_WIN_IF_NAME_LEN + 1]; - char ascii_desc[MAX_WIN_IF_NAME_LEN + 1]; - int i, j; - char errbuf[PCAP_ERRBUF_SIZE]; - if (!has_wpcap) { /* * We don't have Npcap or WinPcap, so we can't get a list of @@ -884,146 +676,7 @@ get_interface_list(int *err, char **err_str) return NULL; } -#ifdef HAVE_PCAP_FINDALLDEVS - if (p_pcap_findalldevs != NULL) - return get_interface_list_findalldevs(err, err_str); -#endif - - /* - * In WinPcap/Npcap, pcap_lookupdev is implemented by calling - * PacketGetAdapterNames. According to the documentation - * I could find: - * - * https://www.winpcap.org/docs/man/html/Packet32_8c.html#a43 - * - * this means that: - * - * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence - * of bytes consisting of: - * - * a sequence of null-terminated ASCII strings (i.e., each - * one is terminated by a single 0 byte), giving the names - * of the interfaces; - * - * an empty ASCII string (i.e., a single 0 byte); - * - * a sequence of null-terminated ASCII strings, giving the - * descriptions of the interfaces; - * - * an empty ASCII string. - * - * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev - * returns a sequence of bytes consisting of: - * - * a sequence of null-terminated double-byte Unicode strings - * (i.e., each one consits of a sequence of double-byte - * characters, terminated by a double-byte 0), giving the - * names of the interfaces; - * - * an empty Unicode string (i.e., a double 0 byte); - * - * a sequence of null-terminated ASCII strings, giving the - * descriptions of the interfaces; - * - * an empty ASCII string. - * - * The Nth string in the first sequence is the name of the Nth - * adapter; the Nth string in the second sequence is the - * description of the Nth adapter. - */ - - names = (wchar_t *)pcap_lookupdev(errbuf); - i = 0; - - if (names) { - char* desc = 0; - int desc_pos = 0; - - if (names[0]<256) { - /* - * If names[0] is less than 256 it means the first - * byte is 0. This implies that we are using Unicode - * characters. - */ - while (*(names+desc_pos) || *(names+desc_pos-1)) - desc_pos++; - desc_pos++; /* Step over the extra '\0' */ - desc = (char*)(names + desc_pos); /* cast *after* addition */ - - while (names[i] != 0) { - /* - * Copy the Unicode description to an ASCII - * string. - */ - j = 0; - while (*desc != 0) { - if (j < MAX_WIN_IF_NAME_LEN) - ascii_desc[j++] = *desc; - desc++; - } - ascii_desc[j] = '\0'; - desc++; - - /* - * Copy the Unicode name to an ASCII string. - */ - j = 0; - while (names[i] != 0) { - if (j < MAX_WIN_IF_NAME_LEN) - ascii_name[j++] = (char) names[i++]; - } - ascii_name[j] = '\0'; - i++; - il = g_list_append(il, - if_info_new(ascii_name, ascii_desc, FALSE)); - } - } else { - /* - * Otherwise we are in Windows 95/98 and using ASCII - * (8-bit) characters. - */ - win95names=(char *)names; - while (*(win95names+desc_pos) || *(win95names+desc_pos-1)) - desc_pos++; - desc_pos++; /* Step over the extra '\0' */ - desc = win95names + desc_pos; - - while (win95names[i] != '\0') { - /* - * "&win95names[i]" points to the current - * interface name, and "desc" points to - * that interface's description. - */ - il = g_list_append(il, - if_info_new(&win95names[i], desc, FALSE)); - - /* - * Skip to the next description. - */ - while (*desc != 0) - desc++; - desc++; - - /* - * Skip to the next name. - */ - while (win95names[i] != 0) - i++; - i++; - } - } - } - - if (il == NULL) { - /* - * No interfaces found. - */ - *err = 0; - if (err_str != NULL) - *err_str = NULL; - } - - return il; + return get_interface_list_findalldevs(err, err_str); } /* @@ -1108,50 +761,11 @@ get_runtime_caplibs_version(GString *str) /* * On Windows, we might have been compiled with WinPcap/Npcap but * might not have it loaded; indicate whether we have it or - * not and, if we have it and we have "pcap_lib_version()", - * what version we have. + * not and, if we have it, what version we have. */ - GModule *handle; /* handle returned by ws_module_open */ - static gchar *packetVer; - gchar *blankp; - if (has_wpcap) { g_string_append_printf(str, "with "); - if (p_pcap_lib_version != NULL) - g_string_append_printf(str, p_pcap_lib_version()); - else { - /* - * An alternative method of obtaining the version - * number, by using the PacketLibraryVersion - * string from packet.dll. - * - * Unfortunately, in WinPcap 3.0, it returns - * "3.0 alpha3", even in the final version of - * WinPcap 3.0, so if there's a blank in the - * string, we strip it and everything after - * it from the string, so we don't misleadingly - * report that 3.0 alpha3 is being used when - * the final version is being used. - */ - if (packetVer == NULL) { - packetVer = "version unknown"; - handle = ws_module_open("packet.dll", 0); - if (handle != NULL) { - if (g_module_symbol(handle, - "PacketLibraryVersion", - (gpointer*)&packetVer)) { - packetVer = g_strdup(packetVer); - blankp = strchr(packetVer, ' '); - if (blankp != NULL) - *blankp = '\0'; - } else { - packetVer = "version unknown"; - } - g_module_close(handle); - } - } - g_string_append_printf(str, "WinPcap (%s)", packetVer); - } + g_string_append_printf(str, p_pcap_lib_version()); } else g_string_append(str, "without Npcap or WinPcap"); } diff --git a/cmake/modules/FindPCAP.cmake b/cmake/modules/FindPCAP.cmake index 6e0393ba26..8955345579 100644 --- a/cmake/modules/FindPCAP.cmake +++ b/cmake/modules/FindPCAP.cmake @@ -182,36 +182,75 @@ if(PCAP_FOUND) set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} ) set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} ) + include(CheckSymbolExists) + if(WIN32) - # Prepopulate some values. WinPcap and Npcap always have these and - # compilation checks on Windows can be slow. - set(HAVE_PCAP_OPEN_DEAD TRUE) + # + # Make sure we have at least the WinPcap 3.1 SDK, because we + # we require at least libpcap 0.8's APIs. 3.1 is based on + # libpcap 0.9.2, but 3.0 is based on a pre-0.8 snapshot of + # libpcap. + # + # We check whether pcap_lib_version is defined in the pcap header, + # using it as a proxy for all the 0.8 API's. if not, we fail. + # + check_symbol_exists( pcap_lib_version ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_LIB_VERSION ) + if( NOT HAVE_PCAP_LIB_VERSION ) + message(FATAL_ERROR "You need WinPcap 3.1 or later, or Npcap") + endif( NOT HAVE_PCAP_LIB_VERSION ) + + # + # Prepopulate some values. WinPcap 3.1 and later, and Npcap, have these + # in their SDK, and compilation checks on Windows can be slow. We check + # whether they're present at run time, when we load wpcap.dll, and work + # around their absence or report an error. + # set(HAVE_PCAP_FREECODE TRUE) - set(HAVE_PCAP_BREAKLOOP TRUE) set(HAVE_PCAP_CREATE TRUE) - set(HAVE_PCAP_DATALINK_NAME_TO_VAL TRUE) - set(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION TRUE) - set(HAVE_PCAP_DATALINK_VAL_TO_NAME TRUE) - set(HAVE_PCAP_FINDALLDEVS TRUE) set(HAVE_PCAP_FREE_DATALINKS TRUE) - set(HAVE_PCAP_LIB_VERSION TRUE) - set(HAVE_PCAP_LIST_DATALINKS TRUE) - set(HAVE_PCAP_SET_DATALINK TRUE) - set(HAVE_BPF_IMAGE TRUE) set(HAVE_PCAP_OPEN TRUE) set(HAVE_PCAP_SETSAMPLING TRUE) + else(WIN32) + # + # Make sure we have at least libpcap 0.8, because we we require at + # least libpcap 0.8's APIs. + # + # We check whether pcap_lib_version is defined in the pcap header, + # using it as a proxy for all the 0.8 API's. if not, we fail. + # + check_symbol_exists( pcap_lib_version ${PCAP_INCLUDE_DIR}/pcap.h HAVE_PCAP_LIB_VERSION ) + if( NOT HAVE_PCAP_LIB_VERSION ) + message(FATAL_ERROR "You need libpcap 0.8 or later") + endif( NOT HAVE_PCAP_LIB_VERSION ) + + check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) + check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) + check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) + check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) + if( HAVE_PCAP_OPEN ) + # + # XXX - this *should* be checked for independently of checking + # for pcap_open(), as you might have pcap_setsampling() without + # remote capture support. + # + # However, 1) the sampling options are treated as remote options + # in the GUI and and 2) having pcap_setsampling() doesn't mean + # you have sampling support. libpcap needs a way to indicate + # whether a given device supports sampling, and the GUI should + # be changed to decouple them. + # + # (Actually, libpcap needs a general mechanism to offer options + # for particular devices, and Wireshark needs to use that + # mechanism. The former is a work in progress.) + # + # (Note: another work in progress is support for remote + # capturing using pcap_create()/pcap_activate(), which we + # also need to support once it's available.) + # + check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) + endif( HAVE_PCAP_OPEN ) endif(WIN32) - check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD ) - check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE ) - # - # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script - # checked for more than just whether the function exists, it also checked - # for whether pcap.h declares it; macOS software/security updates can - # update libpcap without updating the headers. - # - check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP ) - check_function_exists( "pcap_create" HAVE_PCAP_CREATE ) if( HAVE_PCAP_CREATE ) # # If we have pcap_create(), we have pcap_set_buffer_size(), and @@ -222,42 +261,11 @@ if(PCAP_FOUND) # set( CAN_SET_CAPTURE_BUFFER_SIZE TRUE ) endif() - check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL ) - check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION ) - check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME ) - check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS ) - check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS ) - check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD ) - check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION ) - check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS ) - check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK ) - check_function_exists( "bpf_image" HAVE_BPF_IMAGE ) check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION ) check_function_exists( "pcap_set_tstamp_type" HAVE_PCAP_SET_TSTAMP_TYPE ) # Remote pcap checks - check_function_exists( "pcap_open" HAVE_PCAP_OPEN ) if( HAVE_PCAP_OPEN ) set( HAVE_PCAP_REMOTE 1 ) - # - # XXX - this *should* be checked for independently of checking - # for pcap_open(), as you might have pcap_setsampling() without - # remote capture support. - # - # However, 1) the sampling options are treated as remote options - # in the GUI and and 2) having pcap_setsampling() doesn't mean - # you have sampling support. libpcap needs a way to indicate - # whether a given device supports sampling, and the GUI should - # be changed to decouple them. - # - # (Actually, libpcap needs a general mechanism to offer options - # for particular devices, and Wireshark needs to use that - # mechanism. The former is a work in progress.) - # - # (Note: another work in progress is support for remote - # capturing using pcap_create()/pcap_activate(), which we - # also need to support once it's available.) - # - check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING ) endif() cmake_pop_check_state() diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 450a110609..9da6a09dbd 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -40,9 +40,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ARPA_INET_H 1 -/* Define to 1 if you have the `bpf_image' function. */ -#cmakedefine HAVE_BPF_IMAGE 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_FCNTL_H 1 @@ -202,55 +199,24 @@ /* Define to 1 if you have the macOS CFPropertyListCreateWithStream function */ #cmakedefine HAVE_CFPROPERTYLISTCREATEWITHSTREAM 1 -/* Define if pcap_breakloop is known */ -#cmakedefine HAVE_PCAP_BREAKLOOP 1 - /* Define to 1 if you have the `pcap_create' function. */ #cmakedefine HAVE_PCAP_CREATE 1 /* Define to 1 if the capture buffer size can be set. */ #cmakedefine CAN_SET_CAPTURE_BUFFER_SIZE 1 -/* Define to 1 if you have the `pcap_datalink_name_to_val' function. */ -#cmakedefine HAVE_PCAP_DATALINK_NAME_TO_VAL 1 - -/* Define to 1 if you have the `pcap_datalink_val_to_description' function. */ -#cmakedefine HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION 1 - -/* Define to 1 if you have the `pcap_datalink_val_to_name' function. */ -#cmakedefine HAVE_PCAP_DATALINK_VAL_TO_NAME 1 - -/* Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that - declares pcap_if_t. */ -#cmakedefine HAVE_PCAP_FINDALLDEVS 1 - /* Define to 1 if you have the `pcap_freecode' function. */ #cmakedefine HAVE_PCAP_FREECODE 1 /* Define to 1 if you have the `pcap_free_datalinks' function. */ #cmakedefine HAVE_PCAP_FREE_DATALINKS 1 -/* Define to 1 if you have the `pcap_get_selectable_fd' function. */ -#cmakedefine HAVE_PCAP_GET_SELECTABLE_FD 1 - -/* Define to 1 if you have the `pcap_lib_version' function. */ -#cmakedefine HAVE_PCAP_LIB_VERSION 1 - -/* Define to 1 if you have the `pcap_list_datalinks' function. */ -#cmakedefine HAVE_PCAP_LIST_DATALINKS 1 - /* Define to 1 if you have the `pcap_open' function. */ #cmakedefine HAVE_PCAP_OPEN 1 -/* Define to 1 if you have the `pcap_open_dead' function. */ -#cmakedefine HAVE_PCAP_OPEN_DEAD 1 - /* Define to 1 if you have libpcap/WinPcap/Npcap remote capturing support. */ #cmakedefine HAVE_PCAP_REMOTE 1 -/* Define to 1 if you have the `pcap_set_datalink' function. */ -#cmakedefine HAVE_PCAP_SET_DATALINK 1 - /* Define to 1 if you have the `pcap_setsampling' function. */ #cmakedefine HAVE_PCAP_SETSAMPLING 1 diff --git a/dumpcap.c b/dumpcap.c index 6fe9f4887c..86d7b96ee1 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -134,51 +134,7 @@ static void capture_loop_stop(void); /** Close a pipe, or socket if \a from_socket is TRUE */ static void cap_pipe_close(int pipe_fd, gboolean from_socket); -#if !defined (__linux__) -#ifndef HAVE_PCAP_BREAKLOOP -/* - * We don't have pcap_breakloop(), which is the only way to ensure that - * pcap_dispatch(), pcap_loop(), or even pcap_next() or pcap_next_ex() - * won't, if the call to read the next packet or batch of packets is - * is interrupted by a signal on UN*X, just go back and try again to - * read again. - * - * On UN*X, we catch SIGINT as a "stop capturing" signal, and, in - * the signal handler, set a flag to stop capturing; however, without - * a guarantee of that sort, we can't guarantee that we'll stop capturing - * if the read will be retried and won't time out if no packets arrive. - * - * Therefore, on at least some platforms, we work around the lack of - * pcap_breakloop() by doing a select() on the pcap_t's file descriptor - * to wait for packets to arrive, so that we're probably going to be - * blocked in the select() when the signal arrives, and can just bail - * out of the loop at that point. - * - * However, we don't want to do that on BSD (because "select()" doesn't work - * correctly on BPF devices on at least some releases of some flavors of - * BSD), and we don't want to do it on Windows (because "select()" is - * something for sockets, not for arbitrary handles). (Note that "Windows" - * here includes Cygwin; even in its pretend-it's-UNIX environment, we're - * using Npcap, not a UNIX libpcap.) - * - * Fortunately, we don't need to do it on BSD, because the libpcap timeout - * on BSD times out even if no packets have arrived, so we'll eventually - * exit pcap_dispatch() with an indication that no packets have arrived, - * and will break out of the capture loop at that point. - * - * On Windows, we can't send a SIGINT to stop capturing, so none of this - * applies in any case. - * - * XXX - the various BSDs appear to define BSD in ; we don't - * want to include it if it's not present on this platform, however. - */ -# if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && \ - !defined(__bsdi__) && !defined(__APPLE__) && !defined(_WIN32) && \ - !defined(__CYGWIN__) -# define MUST_DO_SELECT -# endif /* avoid select */ -#endif /* HAVE_PCAP_BREAKLOOP */ -#else /* linux */ +#if defined (__linux__) /* whatever the deal with pcap_breakloop, linux doesn't support timeouts * in pcap_dispatch(); on the other hand, select() works just fine there. * Hence we use a select for that come what may. @@ -429,9 +385,7 @@ print_usage(FILE *output) fprintf(output, " -L, --list-data-link-types\n"); fprintf(output, " print list of link-layer types of iface and exit\n"); fprintf(output, " --list-time-stamp-types print list of timestamp types for iface and exit\n"); -#ifdef HAVE_BPF_IMAGE fprintf(output, " -d print generated BPF code for capture filter\n"); -#endif fprintf(output, " -k ,[],[],[]\n"); fprintf(output, " set channel on wifi interface\n"); fprintf(output, " -S print statistics for each interface once per second\n"); @@ -725,7 +679,6 @@ DIAG_ON(cast-qual) return TRUE; } -#ifdef HAVE_BPF_IMAGE static gboolean show_filter_code(capture_options *capture_opts) { @@ -797,7 +750,6 @@ show_filter_code(capture_options *capture_opts) } return TRUE; } -#endif /* * capture_interface_list() is expected to do the right thing to get @@ -2839,11 +2791,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld, /* XXX - will this work for tshark? */ #ifdef MUST_DO_SELECT if (!pcap_src->from_cap_pipe) { -#ifdef HAVE_PCAP_GET_SELECTABLE_FD pcap_src->pcap_fd = pcap_get_selectable_fd(pcap_src->pcap_h); -#else - pcap_src->pcap_fd = pcap_fileno(pcap_src->pcap_h); -#endif } #endif @@ -4192,7 +4140,6 @@ error: static void capture_loop_stop(void) { -#ifdef HAVE_PCAP_BREAKLOOP guint i; capture_src *pcap_src; @@ -4201,7 +4148,6 @@ capture_loop_stop(void) if (pcap_src->pcap_h != NULL) pcap_breakloop(pcap_src->pcap_h); } -#endif global_ld.go = FALSE; } @@ -4627,9 +4573,7 @@ main(int argc, char *argv[]) GLogLevelFlags log_flags; gboolean list_interfaces = FALSE; int caps_queries = 0; -#ifdef HAVE_BPF_IMAGE gboolean print_bpf_code = FALSE; -#endif gboolean set_chan = FALSE; gchar *set_chan_arg = NULL; gboolean machine_readable = FALSE; @@ -4665,12 +4609,6 @@ main(int argc, char *argv[]) ws_init_version_info("Dumpcap (Wireshark)", NULL, get_dumpcap_compiled_info, get_dumpcap_runtime_info); -#ifdef HAVE_BPF_IMAGE -#define OPTSTRING_d "d" -#else -#define OPTSTRING_d -#endif - #ifdef HAVE_PCAP_REMOTE #define OPTSTRING_r "r" #define OPTSTRING_u "u" @@ -4685,7 +4623,7 @@ main(int argc, char *argv[]) #define OPTSTRING_m #endif -#define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:" OPTSTRING_d "ghk:" OPTSTRING_m "MN:nPq" OPTSTRING_r "St" OPTSTRING_u "vw:Z:" +#define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:dghk:" OPTSTRING_m "MN:nPq" OPTSTRING_r "St" OPTSTRING_u "vw:Z:" #ifdef DEBUG_CHILD_DUMPCAP if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) { @@ -5029,14 +4967,12 @@ main(int argc, char *argv[]) case LONGOPT_LIST_TSTAMP_TYPES: caps_queries |= CAPS_QUERY_TIMESTAMP_TYPES; break; -#ifdef HAVE_BPF_IMAGE case 'd': /* Print BPF code for capture filter and exit */ if (!print_bpf_code) { print_bpf_code = TRUE; run_once_args++; } break; -#endif case 'S': /* Print interface statistics once a second */ if (!print_statistics) { print_statistics = TRUE; @@ -5104,11 +5040,7 @@ main(int argc, char *argv[]) } if (run_once_args > 1) { -#ifdef HAVE_BPF_IMAGE cmdarg_err("Only one of -D, -L, -d, -k or -S may be supplied."); -#else - cmdarg_err("Only one of -D, -L, -k or -S may be supplied."); -#endif exit_main(1); } else if (run_once_args == 1) { /* We're supposed to print some information, rather than @@ -5330,12 +5262,10 @@ main(int argc, char *argv[]) /* Process the snapshot length, as that affects the generated BPF code. */ capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE); -#ifdef HAVE_BPF_IMAGE if (print_bpf_code) { show_filter_code(&global_capture_opts); exit_main(0); } -#endif /* We're supposed to do a capture. Process the ring buffer arguments. */ capture_opts_trim_ring_num_files(&global_capture_opts); diff --git a/tshark.c b/tshark.c index d67b0feff0..913ec243ca 100644 --- a/tshark.c +++ b/tshark.c @@ -730,9 +730,7 @@ main(int argc, char *argv[]) gchar *volatile cf_name = NULL; gchar *rfilter = NULL; gchar *dfilter = NULL; -#ifdef HAVE_PCAP_OPEN_DEAD struct bpf_program fcode; -#endif dfilter_t *rfcode = NULL; dfilter_t *dfcode = NULL; e_prefs *prefs_p; @@ -1880,25 +1878,21 @@ main(int argc, char *argv[]) if (rfilter != NULL) { tshark_debug("Compiling read filter: '%s'", rfilter); if (!dfilter_compile(rfilter, &rfcode, &err_msg)) { + pcap_t *pc; + cmdarg_err("%s", err_msg); g_free(err_msg); epan_cleanup(); extcap_cleanup(); -#ifdef HAVE_PCAP_OPEN_DEAD - { - pcap_t *pc; - - pc = pcap_open_dead(DLT_EN10MB, MIN_PACKET_SIZE); - if (pc != NULL) { - if (pcap_compile(pc, &fcode, rfilter, 0, 0) != -1) { - cmdarg_err_cont( - " Note: That read filter code looks like a valid capture filter;\n" - " maybe you mixed them up?"); - } - pcap_close(pc); + pc = pcap_open_dead(DLT_EN10MB, MIN_PACKET_SIZE); + if (pc != NULL) { + if (pcap_compile(pc, &fcode, rfilter, 0, 0) != -1) { + cmdarg_err_cont( + " Note: That read filter code looks like a valid capture filter;\n" + " maybe you mixed them up?"); } + pcap_close(pc); } -#endif exit_status = INVALID_INTERFACE; goto clean_exit; } @@ -1908,25 +1902,21 @@ main(int argc, char *argv[]) if (dfilter != NULL) { tshark_debug("Compiling display filter: '%s'", dfilter); if (!dfilter_compile(dfilter, &dfcode, &err_msg)) { + pcap_t *pc; + cmdarg_err("%s", err_msg); g_free(err_msg); epan_cleanup(); extcap_cleanup(); -#ifdef HAVE_PCAP_OPEN_DEAD - { - pcap_t *pc; - - pc = pcap_open_dead(DLT_EN10MB, MIN_PACKET_SIZE); - if (pc != NULL) { - if (pcap_compile(pc, &fcode, dfilter, 0, 0) != -1) { - cmdarg_err_cont( - " Note: That display filter code looks like a valid capture filter;\n" - " maybe you mixed them up?"); - } - pcap_close(pc); + pc = pcap_open_dead(DLT_EN10MB, MIN_PACKET_SIZE); + if (pc != NULL) { + if (pcap_compile(pc, &fcode, dfilter, 0, 0) != -1) { + cmdarg_err_cont( + " Note: That display filter code looks like a valid capture filter;\n" + " maybe you mixed them up?"); } + pcap_close(pc); } -#endif exit_status = INVALID_FILTER; goto clean_exit; } -- cgit v1.2.3