]> The Tcpdump Group git mirrors - libpcap/commitdiff
Check for loopback adapters on Windows.
authorGuy Harris <[email protected]>
Tue, 28 Jun 2016 09:42:11 +0000 (02:42 -0700)
committerGuy Harris <[email protected]>
Tue, 28 Jun 2016 09:42:11 +0000 (02:42 -0700)
CMakeLists.txt
cmakeconfig.h.in
pcap-win32.c

index ec3362674ff01d03e5eb2524f81b653d09f83f59..a5777082bf54845b6c83572cfc5252a5bc416c8c 100644 (file)
@@ -118,6 +118,13 @@ check_function_exists( strlcpy HAVE_STRLCPY )
 check_function_exists( snprintf HAVE_SNPRINTF )
 check_function_exists( vsnprintf HAVE_VSNPRINTF )
 
+if (WIN32)
+    #
+    # Check for Windows-only functions, such as packet.dll functions.
+    #
+    check_function_exits( PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER )
+endif()
+
 #
 # Data types.
 #
index e3c458c59d04594ec67265f746453a8130a94ac2..603ef14190ede708cde7d9f3f17d5260b171fced 100644 (file)
 /* Define to 1 if you have the `vsnprintf' function. */
 #cmakedefine HAVE_VSNPRINTF 1
 
+/* Define to 1 if you have the `PacketIsLoopbackAdapter' function. */
+#cmakedefine HAVE_PACKET_IS_LOOPBACK_ADAPTER 1
+
 /* define if the system supports zerocopy BPF */
 #cmakedefine HAVE_ZEROCOPY_BPF 1
 
index 13fbb87b949920e956c4362adc52262046e6afd1..17ef874cab898371cd7a06720565165fdcb2d585 100644 (file)
@@ -1233,8 +1233,8 @@ pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
 }
 
 static int
-pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
-    char *errbuf)
+pcap_add_if_win32(pcap_if_t **devlist, char *name, bpf_u_int32 flags,
+    const char *description, char *errbuf)
 {
        pcap_if_t *curdev;
        npf_if_addr if_addrs[MAX_NETWORK_ADDRESSES];
@@ -1246,7 +1246,8 @@ pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
        /*
         * Add an entry for this interface, with no addresses.
         */
-       if (add_or_find_if(&curdev, devlist, name, 0, desc, errbuf) == -1) {
+       if (add_or_find_if(&curdev, devlist, name, flags, description,
+           errbuf) == -1) {
                /*
                 * Failure.
                 */
@@ -1392,10 +1393,32 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
         */
        name = &AdaptersName[0];
        while (*name != '\0') {
+#ifdef HAVE_PACKET_IS_LOOPBACK_ADAPTER
+               bpf_u_int32 flags = 0;
+               pcap_t p;
+
+               /*
+                * Is this a loopback interface?
+                * XXX - it'd be best if there were a way to get a list
+                * of interfaces *and* flags, including "Up" and "Running"
+                * as well as "loopback", without having to open the
+                * interfaces.
+                */
+               p = pcap_open_live(name, 68, 0, 0, errbuf);
+               if (p != NULL) {
+                       if (PacketIsLoopbackAdapter(p->adapter)) {
+                               /* Yes */
+                               flags |= PCAP_IF_LOOPBACK;
+                       }
+                       pcap_close(p);
+               }
+#endif
+
                /*
                 * Add an entry for this interface.
                 */
-               if (pcap_add_if_win32(&devlist, name, desc, errbuf) == -1) {
+               if (pcap_add_if_win32(&devlist, name, flags, desc,
+                   errbuf) == -1) {
                        /*
                         * Failure.
                         */