Index: trunk/src/iphlpapi/iphlpapi.cpp
===================================================================
--- trunk/src/iphlpapi/iphlpapi.cpp	(revision 21412)
+++ trunk/src/iphlpapi/iphlpapi.cpp	(revision 21414)
@@ -47,34 +47,13 @@
 
 #pragma pack(1)
+
 typedef struct
 {
 	unsigned long IPAddress;
-	unsigned short interfaceNum;
+	unsigned short interfaceIndex;
 	unsigned long netmask;
 	unsigned long broadcastAddress;
-} interfaceInformation;
-
-/* Incomplete but will do for us */
-
-#ifndef TCPV40HDRS
-struct ifnet {
-        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
-        short   if_unit;                /* sub-unit for lower level driver */
-        short   if_mtu;                 /* maximum transmission unit */
-};
-#endif
-
-struct ilist {
-  struct ilist *next;
-  unsigned long addr;
-};
-
-struct rlist {
-  struct rlist *next;
-  unsigned long gate;
-  unsigned long net;
-  unsigned long mask;
-  char done;
-};
+}
+AddrInfo;
 
 #pragma pack()
@@ -108,233 +87,290 @@
 static void i_initializeAdapterInformation(void)
 {
-  unsigned char *p;
-  char iShortName[6];
-  struct rlist * rnode = NULL, * rdef = NULL;
-  PIP_ADAPTER_INFO oldAdapter = NULL,topAdapter = NULL;
-  struct sockaddr_in * sin;
-  int rc,i;
-  char *buffer=NULL,*buffer2=NULL;
-  struct ifnet *pifnet;
-  struct ifmib  ifmibget;
-  int cInterfaces;
-#ifndef TCPV40HDRS
-  struct ortentry *r;
-#else
-  struct rtentry *r;
-#endif
-
-  // Init Subsystem and open a socket for ioctl() calls
-  sock_init();
-
-  int clientSocket = socket(PF_INET, SOCK_STREAM, 0);
-  dprintf(("IPHLPAPI(Init): Opened socket %d\n", clientSocket));
-
-  // Whole buf minimum size is 65536 and memsets are really needed in other case
-  // we will get garbage in adapter names.
-
-  buffer = (char*)malloc(64 * 1024);
-  memset(buffer, 0, 65536);
-  memset(&ifmibget,0, sizeof(struct ifmib));
-
-  rc = ioctl(clientSocket, SIOSTATIF, (char*)&ifmibget, sizeof(struct ifmib));
-  dprintf(("IPHLPAPI(SIOSTATIF) ioctl returned: %d\n", rc));
-  if (rc == -1)
-  {
+    char iShortName[8];
+    PIP_ADAPTER_INFO oldAdapter = NULL, topAdapter = NULL;
+    int rc;
+    char *buffer = NULL, *buffer2 = NULL;
+    struct ifmib  ifmibget;
+    int cAddresses;
+    AddrInfo *addrInfo;
+    struct rtentries *rtentries;
+
+    // Init Subsystem and open a socket for ioctl() calls
+    sock_init();
+
+    int clientSocket = socket(PF_INET, SOCK_STREAM, 0);
+    dprintf(("IPHLPAPI: Init: Opened socket %d\n", clientSocket));
+
+    // Whole buf minimum size is 65536 and memsets are really needed in other case
+    // we will get garbage in adapter names.
+
+    memset(&ifmibget,0, sizeof(struct ifmib));
+    buffer = (char*) malloc(65536);
+    memset(buffer, 0, 65536);
+    buffer2 = (char*) malloc(65536);
+    memset(buffer2, 0, 65536);
+
+    rc = ioctl(clientSocket, SIOSTATIF, (char*)&ifmibget, sizeof(struct ifmib));
+    dprintf(("IPHLPAPI: ioctl(SIOSTATIF) returned: %d\n", rc));
+    if (rc == -1)
+    {
+        free(buffer2);
+        free(buffer);
+        soclose(clientSocket);
+        return;
+    }
+    dprintf(("IPHLPAPI: ioctl(SIOSTATIF) returned %d interfaces\n", ifmibget.ifNumber));
+
+    rc = ioctl(clientSocket, SIOSTATAT, buffer, 65536);
+    dprintf(("IPHLPAPI: ioctl(SIOSTATAT) returned: %d\n", rc));
+    if (rc == -1)
+    {
+        free(buffer2);
+        free(buffer);
+        soclose(clientSocket);
+        return;
+    }
+    cAddresses = *(short int *) buffer;
+    addrInfo = (AddrInfo *) (buffer + sizeof(short int));
+    dprintf(("IPHLPAPI: ioctl(SIOSTATAT) returned %d addresses\n", cAddresses));
+
+    rc = ioctl(clientSocket, SIOSTATRT, buffer2, 65536);
+    dprintf(("IPHLPAPI: ioctl(SIOSTATRT) returned: %d\n", rc));
+    if (rc == -1)
+    {
+        free(buffer2);
+        free(buffer);
+        soclose(clientSocket);
+        return;
+    }
+    rtentries = (struct rtentries *) buffer2;
+    dprintf(("IPHLPAPI: ioctl(SIOSTATRT) returned %d host and %d net routes\n",
+             rtentries->hostcount, rtentries->netcount));
+
+    pmibTable = (PMIB_IFTABLE) malloc(ifmibget.ifNumber * sizeof(MIB_IFTABLE));
+    memset(pmibTable, 0, ifmibget.ifNumber * sizeof(MIB_IFTABLE));
+    pmibTable->dwNumEntries = ifmibget.ifNumber;
+
+    pmipaddrTable = (PMIB_IPADDRTABLE) malloc(cAddresses * sizeof(MIB_IPADDRTABLE));
+    memset(pmipaddrTable, 0, cAddresses * sizeof(MIB_IPADDRTABLE));
+    pmipaddrTable->dwNumEntries = cAddresses;
+
+    // loop over interfaces
+    int idx, i;
+    for (i = idx = 0; i < IFMIB_ENTRIES && idx < ifmibget.ifNumber; ++i)
+    {
+        // skip empty interface entries
+        if (ifmibget.iftable[i].ifType == 0)
+            continue;
+
+        short ifIndex = ifmibget.iftable[i].ifIndex;
+        dprintf(("IPHLPAPI: interface index: %u\n", ifIndex));
+
+        // Guess the symbolic interface name. I do not like this very much, but
+        // seems there is no other documented way
+
+        if (ifIndex >= 0 && ifIndex < 9) // lanX
+        {
+            strcpy(iShortName,"lan");
+            iShortName[3] = ifIndex + 48;
+            iShortName[4] = 0;
+        }
+        else
+        if (strstr(ifmibget.iftable[i].ifDescr, "back")) // loopback
+        {
+            strcpy(iShortName,"lo");
+        }
+        else
+        if (strstr(ifmibget.iftable[i].ifDescr, "ace ppp")) // pppX
+        {
+            strcpy(iShortName, strstr(ifmibget.iftable[i].ifDescr, "ppp"));
+        }
+        else
+        if (strstr(ifmibget.iftable[i].ifDescr,"ace sl")) // slX
+        {
+            strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr, "sl"));
+        }
+        else
+        if (strstr(ifmibget.iftable[i].ifDescr,"ace dod")) // dodX
+        {
+            strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr, "dod"));
+        }
+        else // something else...
+        {
+            strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr,"unk"));
+            iShortName[3] = ifIndex + 48;
+            iShortName[4] = 0;
+        }
+
+        dprintf(("IPHLPAPI: interface name: %s [%s]\n", iShortName,
+                 ifmibget.iftable[i].ifDescr));
+
+        // Allocate the adapter info entry
+        pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof (IP_ADAPTER_INFO));
+        memset(pipAdapter, 0, sizeof(IP_ADAPTER_INFO));
+        if (oldAdapter)
+           oldAdapter->Next = pipAdapter;
+
+        // Fill the adapter info entry
+        pipAdapter->Next = NULL;
+        pipAdapter->ComboIndex = 1; // unused according to MSDN
+        strcpy(pipAdapter->AdapterName, ifmibget.iftable[i].ifDescr);
+        strcpy(pipAdapter->Description, ifmibget.iftable[i].ifDescr);
+
+        pipAdapter->AddressLength = sizeof(ifmibget.iftable[i].ifPhysAddr);
+        memcpy(pipAdapter->Address,ifmibget.iftable[i].ifPhysAddr, sizeof(ifmibget.iftable[i].ifPhysAddr));
+        pipAdapter->Index = ifIndex;
+        pipAdapter->Type = ifmibget.iftable[i].ifType; // Careful with this (?)
+
+        // what about OS/2 DHCP?
+        pipAdapter->DhcpEnabled = 0; // Also a question
+        memset((char*)&pipAdapter->DhcpServer, 0, sizeof(IP_ADDR_STRING));
+
+        pipAdapter->HaveWins = 0;
+        memset((char*)&pipAdapter->PrimaryWinsServer, 0, sizeof(IP_ADDR_STRING));
+        memset((char*)&pipAdapter->SecondaryWinsServer, 0, sizeof(IP_ADDR_STRING));
+        pipAdapter->LeaseObtained = 0;
+        pipAdapter->LeaseExpires = 0;
+
+        // Fill the interface table entry
+        MultiByteToWideChar(CP_ACP, 0, iShortName, strlen(iShortName),
+                            pmibTable->table[idx].wszName,
+                            MAX_INTERFACE_NAME_LEN);
+
+        pmibTable->table[idx].dwIndex = ifIndex;
+        pmibTable->table[idx].dwType  = ifmibget.iftable[i].ifType;
+        pmibTable->table[idx].dwMtu   = ifmibget.iftable[i].ifMtu;
+        pmibTable->table[idx].dwSpeed = ifmibget.iftable[i].ifSpeed;
+
+        pmibTable->table[idx].dwPhysAddrLen = sizeof(ifmibget.iftable[i].ifPhysAddr);
+        memcpy(pmibTable->table[idx].bPhysAddr, ifmibget.iftable[i].ifPhysAddr,
+               sizeof(ifmibget.iftable[i].ifPhysAddr));
+
+        pmibTable->table[idx].dwAdminStatus =
+            (ifmibget.iftable[i].ifOperStatus == IFF_UP) ?
+            MIB_IF_ADMIN_STATUS_UP : MIB_IF_ADMIN_STATUS_DOWN;
+        pmibTable->table[idx].dwOperStatus =
+            (ifmibget.iftable[i].ifOperStatus == IFF_UP) ?
+            MIB_IF_OPER_STATUS_OPERATIONAL : MIB_IF_OPER_STATUS_NON_OPERATIONAL;
+
+        pmibTable->table[idx].dwLastChange = ifmibget.iftable[i].ifLastChange;
+        pmibTable->table[idx].dwInOctets   = ifmibget.iftable[i].ifInOctets;
+        pmibTable->table[idx].dwInUcastPkts = ifmibget.iftable[i].ifInUcastPkts;
+        pmibTable->table[idx].dwInNUcastPkts = ifmibget.iftable[i].ifInNUcastPkts;
+        pmibTable->table[idx].dwInDiscards = ifmibget.iftable[i].ifInDiscards;
+        pmibTable->table[idx].dwInErrors = ifmibget.iftable[i].ifInErrors;
+        pmibTable->table[idx].dwInUnknownProtos = ifmibget.iftable[i].ifInUnknownProtos;
+        pmibTable->table[idx].dwOutOctets = ifmibget.iftable[i].ifOutOctets;
+        pmibTable->table[idx].dwOutUcastPkts = ifmibget.iftable[i].ifOutUcastPkts;
+        pmibTable->table[idx].dwOutNUcastPkts = ifmibget.iftable[i].ifOutNUcastPkts;
+        pmibTable->table[idx].dwOutDiscards = ifmibget.iftable[i].ifOutDiscards;
+        pmibTable->table[idx].dwOutErrors = ifmibget.iftable[i].ifOutErrors;
+        pmibTable->table[idx].dwOutQLen = 0; // unused according to MSDN
+
+        pmibTable->table[idx].dwDescrLen = strlen(ifmibget.iftable[i].ifDescr);
+        strncpy((char *)pmibTable->table[idx].bDescr, ifmibget.iftable[i].ifDescr,
+                sizeof(pmibTable->table[idx].bDescr));
+
+        // fill pipAdapter->IpAddressList
+        int cIfAddresses = 0;
+        for (int j = 0; j < cAddresses; ++j)
+        {
+            if (addrInfo[j].interfaceIndex == ifIndex)
+            {
+                ++cIfAddresses;
+
+                IP_ADDR_STRING *addr;
+                if (cIfAddresses == 1)
+                {
+                    addr = &pipAdapter->IpAddressList;
+                }
+                else
+                {
+                    addr->Next = (IP_ADDR_STRING*) malloc(sizeof(IP_ADDR_STRING));
+                    addr = addr->Next;
+                }
+
+                memset((char *) addr, 0, sizeof(IP_ADDR_STRING));
+                addr->Next = NULL;
+                stringIPAddress(addr->IpAddress.String, addrInfo[j].IPAddress);
+                // mask is in network byte order for some reason
+                stringIPAddress(addr->IpMask.String, ntohl(addrInfo[j].netmask));
+                addr->Context = 0;
+            }
+        }
+
+        // fill pipAdapter->GatewayList
+        int cIfGateways = 0;
+        struct rtentry *rtentry = rtentries->rttable;
+        for (j = 0; j < rtentries->hostcount + rtentries->netcount; ++j)
+        {
+            // only take default gateways for this interface
+            if (strcmp(rtentry->rt_ifp->if_name, iShortName) == 0 &&
+                ((struct sockaddr_in *)(&rtentry->rt_dst))->sin_addr.s_addr == 0)
+            {
+                ++cIfGateways;
+
+                IP_ADDR_STRING *addr;
+                if (cIfGateways == 1)
+                {
+                    addr = &pipAdapter->GatewayList;
+                }
+                else
+                {
+                    addr->Next = (IP_ADDR_STRING *) malloc(sizeof(IP_ADDR_STRING));
+                    addr = addr->Next;
+                }
+
+                memset((char *) addr, 0, sizeof(IP_ADDR_STRING));
+                addr->Next = NULL;
+                struct sockaddr_in * sin =
+                    (struct sockaddr_in *)(&rtentry->rt_gateway);
+                strcpy((char *) &addr->IpAddress.String, inet_ntoa(sin->sin_addr));
+                strcpy((char *) &addr->IpMask.String, "255.255.255.255");
+                addr->Context = 0;
+            }
+
+            // For some strange reason, the definition of struct rtentries
+            // is wrong. Each entry in the rtentries::rttable array is followed
+            // by the interface name. Compensate for that.
+            ++rtentry;
+            rtentry = (struct rtentry *)
+                (((char *) rtentry) + strlen(((char *) rtentry)) + 1);
+        }
+
+
+        // loop over
+        if (!topAdapter)
+            topAdapter = pipAdapter;
+        oldAdapter =
+            pipAdapter;
+
+        ++idx;
+    }
+    pipAdapter = topAdapter;
+
+    // loop over addressees to fill pmipaddrTable
+    for (i = 0; i < cAddresses; ++i)
+    {
+        // skip addresses referring to empty interface entries
+        if (addrInfo[i].interfaceIndex >= IFMIB_ENTRIES ||
+            ifmibget.iftable[addrInfo[i].interfaceIndex].ifType == 0)
+            continue;
+
+        pmipaddrTable->table[i].dwAddr = addrInfo[i].IPAddress;
+        pmipaddrTable->table[i].dwIndex = addrInfo[i].interfaceIndex;
+        // mask is in network byte order for some reason
+        pmipaddrTable->table[i].dwMask = ntohl(addrInfo[i].netmask);
+        pmipaddrTable->table[i].dwBCastAddr = addrInfo[i].broadcastAddress;
+        pmipaddrTable->table[i].dwReasmSize = 0; // ?
+    }
+
+    // current address is the first address so far
+    pipAdapter->CurrentIpAddress = &pipAdapter->IpAddressList;
+
+    // Cleanup
+    soclose(clientSocket);
+    free(buffer2);
     free(buffer);
-    soclose(clientSocket);
-    return;
-  }
-
-  rc = ioctl(clientSocket, SIOSTATAT, (char*)buffer, 65536);
-  dprintf(("IPHLPAPI(SIOSTATAT) ioctl returned: %d\n", rc));
-  if (rc == -1)
-  {
-    free(buffer);
-    soclose(clientSocket);
-    return;
-  }
-  cInterfaces = *(short int*)buffer;
-  dprintf(("IPHLPAPI Call returned %d interfaces\n", cInterfaces));
-
-  pmibTable = (PMIB_IFTABLE)malloc(cInterfaces*sizeof(MIB_IFTABLE));
-  memset(pmibTable, 0, cInterfaces*sizeof(MIB_IFTABLE));
-  pmibTable->dwNumEntries = cInterfaces;
-
-  pmipaddrTable = (PMIB_IPADDRTABLE)malloc(cInterfaces*sizeof(MIB_IPADDRTABLE));
-  memset(pmipaddrTable, 0, cInterfaces*sizeof(MIB_IPADDRTABLE));
-  pmipaddrTable->dwNumEntries = cInterfaces;
-
-  for (int currentInterface = 0; currentInterface < cInterfaces; currentInterface++)
-  {
-    interfaceInformation *ifInfo = (interfaceInformation*)(buffer + 2 + (currentInterface * sizeof(interfaceInformation)));
-    // For now let's dump only lanX and pppX adapters, loopback (?)
-//    if (ifInfo->interfaceNum ==9) continue;
-
-    // Allocate and clear mem
-    pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof (IP_ADAPTER_INFO));
-    memset(pipAdapter, 0, sizeof(IP_ADAPTER_INFO));
-    if (oldAdapter)
-       oldAdapter->Next = pipAdapter;
-
-    pipAdapter->Next = NULL;
-    pipAdapter->ComboIndex = 1;
-    i =  ifInfo->interfaceNum;
-    // Gather some other stats
-    dprintf(("IPHLPAPI: interface number: %u\n", ifInfo->interfaceNum));
-
-    if (ifInfo->interfaceNum>=0 && ifInfo->interfaceNum<9) // lanX
-       { strcpy(iShortName,"lan"); iShortName[3] = ifInfo->interfaceNum+48;
-         iShortName[4] = 0;}
-
-    // I do not like this very much, but seems there is no other documented
-    // way
-
-    if (strstr(ifmibget.iftable[i].ifDescr,"back")) // lo
-        strcpy(iShortName,"lo");
-
-    if (strstr(ifmibget.iftable[i].ifDescr,"ace ppp")) // pppX
-        strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr,"ppp"));
-
-    if (strstr(ifmibget.iftable[i].ifDescr,"ace sl")) // slX
-        strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr,"sl"));
-
-    if (strstr(ifmibget.iftable[i].ifDescr,"ace dod")) // dodX
-        strcpy(iShortName,strstr(ifmibget.iftable[i].ifDescr,"dod"));
-
-    dprintf(("IPHLPAPI: interface name[%s] : %s\n",iShortName, ifmibget.iftable[i].ifDescr));
-    strcpy(pipAdapter->AdapterName, ifmibget.iftable[i].ifDescr);
-    strcpy(pipAdapter->Description, ifmibget.iftable[i].ifDescr);
-
-    pipAdapter->AddressLength = 6; // MAX address
-    memcpy(pipAdapter->Address,ifmibget.iftable[i].ifPhysAddr,6);
-    pipAdapter->Index = ifmibget.iftable[i].ifIndex;
-    pipAdapter->Type = ifmibget.iftable[i].ifType; // Careful with this (?)
-    pipAdapter->DhcpEnabled = 0; // Also a question
-
-    MultiByteToWideChar(CP_ACP, 0, iShortName, strlen(iShortName),
-                        pmibTable->table[currentInterface].wszName,
-                        MAX_INTERFACE_NAME_LEN);
-
-    pmibTable->table[currentInterface].dwIndex = ifmibget.iftable[i].ifIndex;
-    pmibTable->table[currentInterface].dwType  = ifmibget.iftable[i].ifType;         /* type of the interface   */
-    pmibTable->table[currentInterface].dwMtu   = ifmibget.iftable[i].ifMtu;          /* MTU of the interface   */
-    pmibTable->table[currentInterface].dwSpeed = ifmibget.iftable[i].ifSpeed;
-
-    pmibTable->table[currentInterface].dwPhysAddrLen = 0; //??
-    memcpy(pmibTable->table[currentInterface].bPhysAddr, ifmibget.iftable[i].ifPhysAddr, sizeof(ifmibget.iftable[i].ifPhysAddr));
-
-    pmibTable->table[currentInterface].dwAdminStatus = ifmibget.iftable[i].ifOperStatus;
-    pmibTable->table[currentInterface].dwOperStatus = (ifmibget.iftable[i].ifOperStatus == IFF_UP) ? MIB_IF_OPER_STATUS_OPERATIONAL : MIB_IF_OPER_STATUS_NON_OPERATIONAL;
-
-    pmibTable->table[currentInterface].dwLastChange = ifmibget.iftable[i].ifLastChange;
-    pmibTable->table[currentInterface].dwInOctets   = ifmibget.iftable[i].ifInOctets;
-    pmibTable->table[currentInterface].dwInUcastPkts = ifmibget.iftable[i].ifInUcastPkts;
-    pmibTable->table[currentInterface].dwInNUcastPkts = ifmibget.iftable[i].ifInNUcastPkts;
-    pmibTable->table[currentInterface].dwInDiscards = ifmibget.iftable[i].ifInDiscards;
-    pmibTable->table[currentInterface].dwInErrors = ifmibget.iftable[i].ifInErrors;
-    pmibTable->table[currentInterface].dwInUnknownProtos = ifmibget.iftable[i].ifInUnknownProtos;
-    pmibTable->table[currentInterface].dwOutOctets = ifmibget.iftable[i].ifOutOctets;
-    pmibTable->table[currentInterface].dwOutUcastPkts = ifmibget.iftable[i].ifOutUcastPkts;
-    pmibTable->table[currentInterface].dwOutNUcastPkts = ifmibget.iftable[i].ifOutNUcastPkts;
-    pmibTable->table[currentInterface].dwOutDiscards = ifmibget.iftable[i].ifOutDiscards;
-    pmibTable->table[currentInterface].dwOutErrors = ifmibget.iftable[i].ifOutErrors;
-//    pmibTable->table[currentInterface].dwOutQLen
-
-    pmibTable->table[currentInterface].dwDescrLen = strlen(ifmibget.iftable[i].ifDescr);
-    strncpy((char *)pmibTable->table[currentInterface].bDescr, ifmibget.iftable[i].ifDescr, sizeof(pmibTable->table[currentInterface].bDescr));
-
-
-    pmipaddrTable->table[currentInterface].dwAddr = ifInfo->IPAddress;
-    // mask is in network byte order for some reason
-    pmipaddrTable->table[currentInterface].dwMask = ntohl(ifInfo->netmask);
-    pmipaddrTable->table[currentInterface].dwBCastAddr = ifInfo->broadcastAddress;
-    pmipaddrTable->table[currentInterface].dwIndex = ifmibget.iftable[i].ifIndex;
-
-    /* MTU of the interface   */
-
-
-
-    // TODO: Adapter may support multiple IP addrs
-    IP_ADDR_STRING iasAdapterIP;
-    iasAdapterIP.Next = NULL;
-    stringIPAddress((char*)&iasAdapterIP.IpAddress,ifInfo->IPAddress);
-    stringIPAddress((char*)&iasAdapterIP.IpMask,ntohl(ifInfo->netmask));
-    iasAdapterIP.Context = 0;
-
-    // Now we are going to catch gateways for this interface
-    buffer2 = (char*) malloc(64*1024);
-    memset(buffer2, 0, 65536);
-
-    rc = ioctl(clientSocket, SIOSTATRT, (char*)buffer2, 65536);
-    dprintf(("IPHLPAPI(SIOSTATRT):ioctl returned: %d\n", rc));
-
-    if (rc == -1)
-    {
-      free(buffer);
-      free(buffer2);
-      soclose(clientSocket);
-      // better return nothing than some trash, unwinding and freeing
-      for (topAdapter; pipAdapter; topAdapter = pipAdapter) {
-          pipAdapter = topAdapter -> Next;
-          free(topAdapter);
-      }
-      return;
-     }
-
-     rtentries *routeEntries = (rtentries*)buffer2;
-     p = (unsigned char *)&routeEntries->rttable[0];
-
-     IP_ADDR_STRING iasGateway;
-     memset(&iasGateway,0,sizeof(iasGateway));
-
-     for (int currentRoute = 0; currentRoute < (routeEntries->hostcount+routeEntries->netcount); currentRoute++)
-     {
-     // First check if this route is for our interface
-#ifndef TCPV40HDRS
-         r = (struct ortentry *) (p);
-#else
-         r = (struct rtentry *) (p);
-#endif
-         if (strcmp((const char*)(p + sizeof(struct rtentry)),iShortName)==0)
-         {
-            sin = (struct sockaddr_in *)(&r->rt_dst);
-            if (strcmp(inet_ntoa(sin->sin_addr),"0.0.0.0")==0)
-            {
-               iasGateway.Next = NULL;
-	       // TODO : Some systems may have many gateways
-               sin = (struct sockaddr_in *)(&r->rt_gateway);
-               strcpy(iasGateway.IpAddress.String,inet_ntoa(sin->sin_addr));
-               sin = (struct sockaddr_in *)&p[-4];
-               strcpy(iasGateway.IpMask.String,inet_ntoa(sin->sin_addr));
-               iasGateway.Context = 0;
-            }
-         }
-#ifndef TCPV40HDRS
-       p+=sizeof(struct ortentry);
-#else
-       p+=sizeof(struct rtentry);
-#endif
-       p+=strlen((char *)p)+1;
-    }
-
-  memcpy((char*)&pipAdapter->IpAddressList, (char*)&iasAdapterIP, sizeof(iasAdapterIP));
-  pipAdapter->CurrentIpAddress = &pipAdapter->IpAddressList;
-  memcpy((char*)&pipAdapter->GatewayList,   (char*)&iasGateway, sizeof(iasGateway));
-  // what about OS/2 DHCP?
-  memset((char*)&pipAdapter->DhcpServer, 0, sizeof( IP_ADDR_STRING ) );
-  pipAdapter->HaveWins = 0;
-  memset((char*)&pipAdapter->PrimaryWinsServer, 0, sizeof( IP_ADDR_STRING ) );
-  memset((char*)&pipAdapter->SecondaryWinsServer, 0, sizeof( IP_ADDR_STRING ) );
-  pipAdapter->LeaseObtained = 0;
-  pipAdapter->LeaseExpires = 0;
-  if (!topAdapter) topAdapter = pipAdapter;
-  oldAdapter = pipAdapter;
- }
- pipAdapter = topAdapter;
-
- // Cleanup
- if (buffer) free(buffer);
- if (buffer2) free(buffer2);
- soclose(clientSocket);
 }
 
