aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--cmakeconfig.h.in3
-rw-r--r--pcap-win32.c31
3 files changed, 37 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec336267..a5777082 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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.
#
diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in
index e3c458c5..603ef141 100644
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -208,6 +208,9 @@
/* 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
diff --git a/pcap-win32.c b/pcap-win32.c
index 13fbb87b..17ef874c 100644
--- a/pcap-win32.c
+++ b/pcap-win32.c
@@ -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.
*/