From 9d43e8f0e0a537f7d89920fbc51b7332d1b3ca18 Mon Sep 17 00:00:00 2001 From: hsluoyz Date: Tue, 25 Aug 2015 13:39:09 +0800 Subject: [PATCH] PCAP_IF_LOOPBACK flag in pcap_if_t struct will be set for "Npcap Loopback Adapter" now, only for DLT_NULL mode. --- wpcap/libpcap/inet.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wpcap/libpcap/inet.c b/wpcap/libpcap/inet.c index aad87963..cbabee8b 100644 --- a/wpcap/libpcap/inet.c +++ b/wpcap/libpcap/inet.c @@ -133,6 +133,7 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name, pcap_t *p; pcap_if_t *curdev, *prevdev, *nextdev; int this_instance; + int npcap_loopback = 0; /* * Is there already an entry in the list for this interface? @@ -205,6 +206,24 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name, *curdev_ret = NULL; return (0); } + else { + NetType type; + /* + * Set PCAP_IF_LOOPBACK for "Npcap Loopback Adapter". + */ + if (PacketGetNetType(p->adapter, &type) == FALSE) { + (void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "Cannot determine the network type: %s", pcap_win32strerror()); + } + else { + if (type.LinkType == NdisMediumNull) { + npcap_loopback = 1; + } + else { + npcap_loopback = 0; + } + } + } pcap_close(p); /* @@ -251,6 +270,8 @@ add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name, curdev->flags = 0; if (ISLOOPBACK(name, flags)) curdev->flags |= PCAP_IF_LOOPBACK; + if (npcap_loopback) + curdev->flags |= PCAP_IF_LOOPBACK; /* * Add it to the list, in the appropriate location.