changeset 7748:12e628d78897

7158636: InterfaceAddress.getBroadcast() returns invalid broadcast address on WLAN Summary: Update Windows native code to infer WLAN interface type in Windows Vista and later Reviewed-by: chegar, alanb
author robm
date Thu, 28 Aug 2014 18:01:16 +0100
parents f982f9fdb8e8
children 182b3e8a732d
files src/windows/native/java/net/NetworkInterface.c src/windows/native/java/net/NetworkInterface.h
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/NetworkInterface.c	Wed Sep 03 22:56:21 2014 -0700
+++ b/src/windows/native/java/net/NetworkInterface.c	Thu Aug 28 18:01:16 2014 +0100
@@ -175,7 +175,7 @@
     int count;
     netif *netifP;
     DWORD i;
-    int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, net=0, wlen=0;
+    int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, wlan=0, net=0, wlen=0;
 
     /*
      * Ask the IP Helper library to enumerate the adapters
@@ -215,15 +215,15 @@
          */
         switch (ifrowP->dwType) {
             case MIB_IF_TYPE_ETHERNET:
-                sprintf(dev_name, "eth%d", eth++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "eth%d", eth++);
                 break;
 
             case MIB_IF_TYPE_TOKENRING:
-                sprintf(dev_name, "tr%d", tr++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "tr%d", tr++);
                 break;
 
             case MIB_IF_TYPE_FDDI:
-                sprintf(dev_name, "fddi%d", fddi++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "fddi%d", fddi++);
                 break;
 
             case MIB_IF_TYPE_LOOPBACK:
@@ -231,20 +231,24 @@
                 if (lo > 0) {
                     continue;
                 }
-                strcpy(dev_name, "lo");
+                strncpy_s(dev_name, 8, "lo", _TRUNCATE);
                 lo++;
                 break;
 
             case MIB_IF_TYPE_PPP:
-                sprintf(dev_name, "ppp%d", ppp++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "ppp%d", ppp++);
                 break;
 
             case MIB_IF_TYPE_SLIP:
-                sprintf(dev_name, "sl%d", sl++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "sl%d", sl++);
+                break;
+
+            case IF_TYPE_IEEE80211:
+                _snprintf_s(dev_name, 8, _TRUNCATE, "wlan%d", wlan++);
                 break;
 
             default:
-                sprintf(dev_name, "net%d", net++);
+                _snprintf_s(dev_name, 8, _TRUNCATE, "net%d", net++);
         }
 
         /*
@@ -409,6 +413,7 @@
             case MIB_IF_TYPE_TOKENRING:
             case MIB_IF_TYPE_FDDI:
             case MIB_IF_TYPE_LOOPBACK:
+            case IF_TYPE_IEEE80211:
               /**
                * Contrary to what it seems to indicate, dwBCastAddr doesn't
                * contain the broadcast address but 0 or 1 depending on whether
@@ -949,6 +954,7 @@
       case MIB_IF_TYPE_ETHERNET:
       case MIB_IF_TYPE_TOKENRING:
       case MIB_IF_TYPE_FDDI:
+      case IF_TYPE_IEEE80211:
         len = ifRowP->dwPhysAddrLen;
         ret = (*env)->NewByteArray(env, len);
         if (!IS_NULL(ret)) {
--- a/src/windows/native/java/net/NetworkInterface.h	Wed Sep 03 22:56:21 2014 -0700
+++ b/src/windows/native/java/net/NetworkInterface.h	Thu Aug 28 18:01:16 2014 +0100
@@ -88,4 +88,9 @@
 
 int enumInterfaces(JNIEnv *env, netif **netifPP);
 
+// Windows Visa (and later) only.....
+#ifndef IF_TYPE_IEEE80211
+#define IF_TYPE_IEEE80211     71
 #endif
+
+#endif