[jbossnative-commits] JBoss Native SVN: r1014 - in trunk/sight: native/os/windows and 1 other directory.

jbossnative-commits at lists.jboss.org jbossnative-commits at lists.jboss.org
Mon Sep 10 08:42:43 EDT 2007


Author: mladen.turk at jboss.com
Date: 2007-09-10 08:42:43 -0400 (Mon, 10 Sep 2007)
New Revision: 1014

Modified:
   trunk/sight/examples/org/jboss/sight/ListAdapters.java
   trunk/sight/native/os/windows/netadapter.c
Log:
Create pseduo interface names like in JDK

Modified: trunk/sight/examples/org/jboss/sight/ListAdapters.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListAdapters.java	2007-09-10 10:31:21 UTC (rev 1013)
+++ trunk/sight/examples/org/jboss/sight/ListAdapters.java	2007-09-10 12:42:43 UTC (rev 1014)
@@ -50,6 +50,7 @@
             System.out.println("Adapters");
             for (NetworkAdapter a : NetworkAdapter.getAdapters()) {
                 System.out.println("Adapter: " + a.FriendlyName);
+                System.out.println("         " + a.Name);
                 System.out.println("         " + a.Description);
                 System.out.println("         " + a.Type);
                 System.out.println("         " + a.OperationalStatus);

Modified: trunk/sight/native/os/windows/netadapter.c
===================================================================
--- trunk/sight/native/os/windows/netadapter.c	2007-09-10 10:31:21 UTC (rev 1013)
+++ trunk/sight/native/os/windows/netadapter.c	2007-09-10 12:42:43 UTC (rev 1014)
@@ -145,8 +145,71 @@
     PIP_ADAPTER_ADDRESSES pCurrent;
     PIP_ADAPTER_INFO      pInfo;
     PIP_ADAPTER_INFO      pCurInfo;
+    int                   devCounters[8];
+    PMIB_IFTABLE          pTable;
 } net_adapter_enum_t;
 
+static int if_enum(SIGHT_STDARGS, net_adapter_enum_t *e)
+{
+    DWORD i, rc;
+    DWORD dwSize;
+
+    dwSize = sizeof(MIB_IFTABLE);
+    if (!(e->pTable = sight_calloc(_E, dwSize, THROW_FMARK)))
+        return errno;
+
+    rc = GetIfTable(e->pTable, &dwSize, TRUE);
+    if (rc == ERROR_INSUFFICIENT_BUFFER || rc == ERROR_BUFFER_OVERFLOW) {
+        free(e->pTable);
+        if (!(e->pTable = sight_calloc(_E, dwSize, THROW_FMARK)))
+            return errno;
+        rc = GetIfTable(e->pTable, &dwSize, TRUE);
+    }
+    for (i = 0; i < e->pTable->dwNumEntries; i++) {
+        switch (e->pTable->table[i].dwType) {
+            case MIB_IF_TYPE_ETHERNET:
+                swprintf(e->pTable->table[i].wszName, L"eth%d",  e->devCounters[0]++);
+            break;
+            case MIB_IF_TYPE_TOKENRING:
+                swprintf(e->pTable->table[i].wszName, L"tr%d",   e->devCounters[1]++);
+            break;
+            case MIB_IF_TYPE_FDDI:
+                swprintf(e->pTable->table[i].wszName, L"fddi%d", e->devCounters[2]++);
+            break;
+            case MIB_IF_TYPE_LOOPBACK:
+                /* There should only be only IPv4 loopback address */
+                if (e->devCounters[3]++ == 0)
+                    lstrcpyW(e->pTable->table[i].wszName, L"lo");
+                else
+                    continue;
+                break;
+            case MIB_IF_TYPE_PPP:
+                swprintf(e->pTable->table[i].wszName, L"ppp%d",  e->devCounters[3]++);
+            break;
+            case MIB_IF_TYPE_SLIP:
+                swprintf(e->pTable->table[i].wszName, L"sl%d",   e->devCounters[4]++);
+            break;
+            default:
+                swprintf(e->pTable->table[i].wszName, L"net%d",  e->devCounters[5]++);
+            break;
+        }
+    }
+    return rc;
+}
+
+static int if_name(net_adapter_enum_t *e, PIP_ADAPTER_ADDRESSES a, LPWSTR dst)
+{
+    DWORD i;
+
+    for (i = 0; i < e->pTable->dwNumEntries; i++) {
+        if (e->pTable->table[i].dwIndex == a->IfIndex) {
+            lstrcpyW(dst, e->pTable->table[i].wszName);
+            return 1;
+        }
+    }
+    return 0;
+}
+
 static jlong xp_enum0(SIGHT_STDARGS, jlong pool)
 {
     DWORD rc;
@@ -187,12 +250,14 @@
         throwAprException(_E, APR_FROM_OS_ERROR(rc));
         goto cleanup;
     }
+    if (if_enum(_E, _O, e) != ERROR_SUCCESS)
+        goto cleanup;
     e->pCurrent = e->pAddresses;
     return P2J(e);
 cleanup:
     if (e) {
-        if (e->pAddresses)
-            free(e->pAddresses);
+        SIGHT_FREE(e->pAddresses);
+        SIGHT_FREE(e->pTable);
         free(e);
     }
     return 0;
@@ -231,13 +296,16 @@
         throwAprException(_E, APR_FROM_OS_ERROR(rc));
         goto cleanup;
     }
+    if (if_enum(_E, _O, e) != ERROR_SUCCESS)
+        goto cleanup;
+
     e->pCurInfo = e->pInfo;
     e->isInfo   = 1;
     return P2J(e);
 cleanup:
     if (e) {
-        if (e->pInfo)
-            free(e->pInfo);
+        SIGHT_FREE(e->pInfo);
+        SIGHT_FREE(e->pTable);
         free(e);
     }
     return 0;
@@ -288,13 +356,23 @@
     PIP_ADAPTER_DNS_SERVER_ADDRESS  da;
     jsize len, idx, i;
     char buf[MAX_PATH] = {0};
+    WCHAR nname[32];
     char *sp;
     DWORD blen;
     UNREFERENCED_O;
     if (!e || !e->pCurrent)
         return;
 
-    SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
+    if (if_name(e, e->pCurrent, nname))
+        SET_IFIELD_W(0000, thiz, nname);
+    else {
+        if (e->pCurrent->IfType == IF_TYPE_TUNNEL) {
+            sprintf(buf, "tun%d", e->devCounters[6]++);
+            SET_IFIELD_S(0000, thiz, buf);
+        }
+        else
+            SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
+    }
     SET_IFIELD_W(0001, thiz, e->pCurrent->Description);
     SET_IFIELD_W(0002, thiz, e->pCurrent->FriendlyName);
     CALL_METHOD1(0000, thiz, e->pCurrent->IfType);
@@ -480,13 +558,17 @@
     PIP_ADDR_STRING ua;
     PIP_ADDR_STRING da;
     char buf[MAX_PATH];
+    WCHAR nname[32];
     char *sp;
     jsize len, idx, i;
     UNREFERENCED_O;
     if (!e || !e->pCurInfo)
         return;
 
-    SET_IFIELD_S(0000, thiz, e->pCurInfo->AdapterName);
+    if (if_name(e, e->pCurrent, nname))
+        SET_IFIELD_W(0000, thiz, nname);
+    else
+        SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
     SET_IFIELD_S(0001, thiz, e->pCurInfo->Description);
     SET_IFIELD_S(0002, thiz, e->pCurInfo->AdapterName);
     CALL_METHOD1(0000, thiz, e->pCurInfo->Type);
@@ -652,10 +734,9 @@
 
     UNREFERENCED_STDARGS;
     if (e) {
-        if (e->pAddresses)
-            free(e->pAddresses);
-        if (e->pInfo)
-            free(e->pInfo);
+        SIGHT_FREE(e->pAddresses);
+        SIGHT_FREE(e->pInfo);
+        SIGHT_FREE(e->pTable);
         free(e);
     }
 }




More information about the jbossnative-commits mailing list