]> The Tcpdump Group git mirrors - libpcap/commitdiff
pcap_create_interface() needs the interface name on Linux.
authorGuy Harris <[email protected]>
Thu, 30 Jun 2016 18:19:57 +0000 (11:19 -0700)
committerGuy Harris <[email protected]>
Thu, 30 Jun 2016 18:20:21 +0000 (11:20 -0700)
So pass it the interface name, and use the name passed to it rather than
the name in the pcap_t - which hasn't yet been set at that point.

14 files changed:
pcap-bpf.c
pcap-dlpi.c
pcap-dos.c
pcap-int.h
pcap-libdlpi.c
pcap-linux.c
pcap-nit.c
pcap-null.c
pcap-pf.c
pcap-sita.c
pcap-snit.c
pcap-snoop.c
pcap-win32.c
pcap.c

index b612b04e1f2faf76301ebc56a3bd9ad2226dfbff..b7fe0856959e485a4d446f15f3ff34507e43c360 100644 (file)
@@ -429,7 +429,7 @@ pcap_ack_zbuf(pcap_t *p)
 #endif /* HAVE_ZEROCOPY_BPF */
 
 pcap_t *
 #endif /* HAVE_ZEROCOPY_BPF */
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index 623c5c21854cf0544730ae2ecb7a963730814ceb..075d0cb3786455194d71fd0164250bb65c0d83dd 100644 (file)
@@ -1812,7 +1812,7 @@ dlpi_kread(register int fd, register off_t addr,
 #endif
 
 pcap_t *
 #endif
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 #ifdef DL_HP_RAWDLS
 {
        pcap_t *p;
 #ifdef DL_HP_RAWDLS
index f42b394b06c1ed2835d6b7a27b45807b5fef065b..ea6b225a23efaa6bacb607223955262ce968cdcb 100644 (file)
@@ -149,7 +149,7 @@ struct pcap_dos {
        struct pcap_stat stat;
 };
 
        struct pcap_stat stat;
 };
 
-pcap_t *pcap_create_interface (char *ebuf)
+pcap_t *pcap_create_interface (const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index d88331dfe97072f3258d9b1b8fb7c4ebf2422999..c5a030f5fe5435cebbe21bde9ecb873adb14423d 100644 (file)
@@ -446,7 +446,7 @@ int pcap_setnonblock_fd(pcap_t *p, int, char *);
  * "pcap_create_common()" allocates and fills in a pcap_t, for use
  * by pcap_create routines.
  */
  * "pcap_create_common()" allocates and fills in a pcap_t, for use
  * by pcap_create routines.
  */
-pcap_t *pcap_create_interface(char *);
+pcap_t *pcap_create_interface(const char *, char *);
 pcap_t *pcap_create_common(char *, size_t);
 int    pcap_do_addexit(pcap_t *);
 void   pcap_add_to_pcaps_to_close(pcap_t *);
 pcap_t *pcap_create_common(char *, size_t);
 int    pcap_do_addexit(pcap_t *);
 void   pcap_add_to_pcaps_to_close(pcap_t *);
index 0bbc96cc0aee49809fbc314eae0b580a47b79732..625f1e0a31ed5168000f626b8a68aa633d2e6e6f 100644 (file)
@@ -426,7 +426,7 @@ pcap_libdlpi_err(const char *linkname, const char *func, int err, char *errbuf)
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index ea38fff50ac1bf2dcae4087fab4c96cd41ddc8f3..8aea72cb076da8c18bd9d7cb07c5e9004e467840 100644 (file)
@@ -433,7 +433,8 @@ static int  enter_rfmon_mode(pcap_t *handle, int sock_fd,
     const char *device);
 #endif /* HAVE_PF_PACKET_SOCKETS */
 #if defined(HAVE_LINUX_NET_TSTAMP_H) && defined(PACKET_TIMESTAMP)
     const char *device);
 #endif /* HAVE_PF_PACKET_SOCKETS */
 #if defined(HAVE_LINUX_NET_TSTAMP_H) && defined(PACKET_TIMESTAMP)
-static int     iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf);
+static int     iface_ethtool_get_ts_info(const char *device, pcap_t *handle,
+    char *ebuf);
 #endif
 #ifdef HAVE_PACKET_RING
 static int     iface_get_offload(pcap_t *handle);
 #endif
 #ifdef HAVE_PACKET_RING
 static int     iface_get_offload(pcap_t *handle);
@@ -454,7 +455,7 @@ static struct sock_fprog    total_fcode
 #endif /* SO_ATTACH_FILTER */
 
 pcap_t *
 #endif /* SO_ATTACH_FILTER */
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
 {
        pcap_t *handle;
 
 {
        pcap_t *handle;
 
@@ -469,7 +470,7 @@ pcap_create_interface(char *ebuf)
        /*
         * See what time stamp types we support.
         */
        /*
         * See what time stamp types we support.
         */
-       if (iface_ethtool_get_ts_info(handle, ebuf) == -1) {
+       if (iface_ethtool_get_ts_info(device, handle, ebuf) == -1) {
                pcap_close(handle);
                return NULL;
        }
                pcap_close(handle);
                return NULL;
        }
@@ -6028,7 +6029,7 @@ iface_set_all_ts_types(pcap_t *handle)
  * Get a list of time stamping capabilities.
  */
 static int
  * Get a list of time stamping capabilities.
  */
 static int
-iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
+iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf)
 {
        int fd;
        struct ifreq ifr;
 {
        int fd;
        struct ifreq ifr;
@@ -6043,7 +6044,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
         * and not all devices even necessarily *support* hardware time
         * stamping, so don't report any time stamp types.
         */
         * and not all devices even necessarily *support* hardware time
         * stamping, so don't report any time stamp types.
         */
-       if (strcmp(handle->opt.device, "any") == 0) {
+       if (strcmp(device, "any") == 0) {
                handle->tstamp_type_list = NULL;
                return 0;
        }
                handle->tstamp_type_list = NULL;
                return 0;
        }
@@ -6059,7 +6060,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
        }
 
        memset(&ifr, 0, sizeof(ifr));
        }
 
        memset(&ifr, 0, sizeof(ifr));
-       strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
+       strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
        memset(&info, 0, sizeof(info));
        info.cmd = ETHTOOL_GET_TS_INFO;
        ifr.ifr_data = (caddr_t)&info;
        memset(&info, 0, sizeof(info));
        info.cmd = ETHTOOL_GET_TS_INFO;
        ifr.ifr_data = (caddr_t)&info;
@@ -6094,7 +6095,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
                         * Other error.
                         */
                        pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
                         * Other error.
                         */
                        pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
-                           "%s: SIOCETHTOOL(ETHTOOL_GET_TS_INFO) ioctl failed: %s", handle->opt.device,
+                           "%s: SIOCETHTOOL(ETHTOOL_GET_TS_INFO) ioctl failed: %s", device,
                            strerror(save_errno));
                        return -1;
                }
                            strerror(save_errno));
                        return -1;
                }
@@ -6139,7 +6140,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf)
 }
 #else /* ETHTOOL_GET_TS_INFO */
 static int
 }
 #else /* ETHTOOL_GET_TS_INFO */
 static int
-iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf _U_)
+iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf _U_)
 {
        /*
         * This doesn't apply to the "any" device; you can't say "turn on
 {
        /*
         * This doesn't apply to the "any" device; you can't say "turn on
@@ -6148,7 +6149,7 @@ iface_ethtool_get_ts_info(pcap_t *handle, char *ebuf _U_)
         * and not all devices even necessarily *support* hardware time
         * stamping, so don't report any time stamp types.
         */
         * and not all devices even necessarily *support* hardware time
         * stamping, so don't report any time stamp types.
         */
-       if (strcmp(handle->opt.device, "any") == 0) {
+       if (strcmp(device, "any") == 0) {
                handle->tstamp_type_list = NULL;
                return 0;
        }
                handle->tstamp_type_list = NULL;
                return 0;
        }
index ce3e52a586c98c3b4d2cb0ee1a7377a044c8c917..1b626e215a22cc20f6c3c23e43b807ac2cba619e 100644 (file)
@@ -355,7 +355,7 @@ pcap_activate_nit(pcap_t *p)
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index af46b8c7a280e14533d5297b8766b58fa436b0f5..b5fa3ab91fabfc576a22796e402ab9728ecd6d8b 100644 (file)
@@ -36,7 +36,7 @@
 static char nosup[] = "live packet capture not supported on this system";
 
 pcap_t *
 static char nosup[] = "live packet capture not supported on this system";
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        (void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
        return (NULL);
 {
        (void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
        return (NULL);
index 00e9107e5f6ac7cb7d1a2532b098ef7b5bf89634..0a7f45881dec5c8cd0eafa407b8e18bf8bef275d 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -506,7 +506,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n",
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index 123700d3e0881d025497a551a736647803473698..1cd5f7510a0414fcf92b91e12aab6b3d8e357f50 100644 (file)
@@ -1014,7 +1014,7 @@ static int pcap_activate_sita(pcap_t *handle) {
        return 0;
 }
 
        return 0;
 }
 
-pcap_t *pcap_create_interface(char *ebuf) {
+pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
        pcap_t *p;
 
        p = pcap_create_common(ebuf, 0);
        pcap_t *p;
 
        p = pcap_create_common(ebuf, 0);
index ae8dd8bde2a853880d7a5b55f27e79922598097c..7db2fd9a61cf052244e8ca3c7d5e3e672f21f486 100644 (file)
@@ -431,7 +431,7 @@ pcap_activate_snit(pcap_t *p)
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index cdee48b5091bf0ea0c32b0d83dc77a4104f9f725..687b1d907b4f3a9273df1732e90ffb32996dc1f3 100644 (file)
@@ -406,7 +406,7 @@ pcap_activate_snoop(pcap_t *p)
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
index 0e380ea60c8e3fc177a2626a6fe72e8432cd68f9..c6621c5bd55cf5ee13f3c7c32fee9b833de67d91 100644 (file)
@@ -1062,7 +1062,7 @@ bad:
 }
 
 pcap_t *
 }
 
 pcap_t *
-pcap_create_interface(char *ebuf)
+pcap_create_interface(const char *device _U_, char *ebuf)
 {
        pcap_t *p;
 
 {
        pcap_t *p;
 
diff --git a/pcap.c b/pcap.c
index 701f9acee6b347c296cdf5a3cf51c2bdfcddb1ba..c968cc67a3564e500b5a25db874eea02e54f8c0c 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -506,7 +506,7 @@ pcap_create(const char *device, char *errbuf)
        /*
         * OK, try it as a regular network interface.
         */
        /*
         * OK, try it as a regular network interface.
         */
-       p = pcap_create_interface(errbuf);
+       p = pcap_create_interface(device_str, errbuf);
        if (p == NULL) {
                /*
                 * We assume the caller filled in errbuf.
        if (p == NULL) {
                /*
                 * We assume the caller filled in errbuf.