Ignore:
Timestamp:
Jan 18, 2011, 1:00:16 PM (15 years ago)
Author:
dmik
Message:

iphlpapi: Fixed a crash when building the adapter/interface/address tables due to a bogus ioctl(SIOSTATRT) implementation in OS/2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/iphlpapi/iphlpapi.cpp

    r21480 r21563  
    2727
    2828#include <types.h>
    29 #include <sys\socket.h>
    30 #include <sys\ioctl.h>
    31 #include <net\route.h>
    32 #include <net\if.h>
    33 #include <net\if_arp.h>
     29#include <sys/socket.h>
     30#include <sys/ioctl.h>
     31#include <net/route.h>
     32#include <net/if.h>
     33#include <net/if_arp.h>
    3434#ifdef TCPV40HDRS
    35 #include <netinet\in.h>
    36 #include <arpa\NAMESER.H>
     35#include <netinet/in.h>
     36#include <arpa/NAMESER.H>
    3737#endif
    3838#include <resolv.h>
     
    5050typedef struct
    5151{
    52         unsigned long IPAddress;
    53         unsigned short interfaceIndex;
    54         unsigned long netmask;
    55         unsigned long broadcastAddress;
     52    unsigned long IPAddress;
     53    unsigned short interfaceIndex;
     54    unsigned long netmask;
     55    unsigned long broadcastAddress;
    5656}
    5757AddrInfo;
     
    7979{
    8080    sprintf(dst, "%u.%u.%u.%u",
    81                         (char)data,
    82                         (char)(*(((char*)&data) + 1)),
    83                         (char)(*(((char*)&data) + 2)),
    84                         (char)(*(((char*)&data) + 3)));
     81            (char)data,
     82            (char)(*(((char*)&data) + 1)),
     83            (char)(*(((char*)&data) + 2)),
     84            (char)(*(((char*)&data) + 3)));
    8585}
    8686
     
    207207
    208208        // Allocate the adapter info entry
    209         pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof (IP_ADAPTER_INFO));
     209        pipAdapter = (PIP_ADAPTER_INFO)malloc (sizeof(IP_ADAPTER_INFO));
    210210        memset(pipAdapter, 0, sizeof(IP_ADAPTER_INFO));
    211211        if (oldAdapter)
     
    276276        for (int j = 0; j < cAddresses; ++j)
    277277        {
     278#ifdef DEBUG
     279            if (i == 0) // print only once
     280            {
     281                dprintf(("IPHLPAPI: ADDR %d:", j));
     282                dprintf(("IPHLPAPI:   IPAddress         0x%08X", addrInfo[j].IPAddress));
     283                dprintf(("IPHLPAPI:   interfaceIndex    %d", addrInfo[j].interfaceIndex));
     284                dprintf(("IPHLPAPI:   netmask           0x%08X", addrInfo[j].netmask));
     285                dprintf(("IPHLPAPI:   broadcastAddress  0x%08X", addrInfo[j].broadcastAddress));
     286            }
     287#endif
    278288            if (addrInfo[j].interfaceIndex == ifIndex)
    279289            {
     
    305315        for (j = 0; j < rtentries->hostcount + rtentries->netcount; ++j)
    306316        {
     317#ifdef DEBUG
     318            if (i == 0) // print only once
     319            {
     320                dprintf(("IPHLPAPI: RTENTRY %d:", j));
     321                dprintf(("IPHLPAPI:   rt_hash     0x%08X", rtentry->rt_hash));
     322                dprintf(("IPHLPAPI:   rt_dst      0x%08X", ((struct sockaddr_in *)(&rtentry->rt_dst))->sin_addr.s_addr));
     323                dprintf(("IPHLPAPI:   rt_gateway  0x%08X", ((struct sockaddr_in *)(&rtentry->rt_gateway))->sin_addr.s_addr));
     324                dprintf(("IPHLPAPI:   rt_flags    0x%08X", rtentry->rt_flags));
     325                dprintf(("IPHLPAPI:   rt_refcnt   %d", rtentry->rt_refcnt));
     326                dprintf(("IPHLPAPI:   rt_use      %d", rtentry->rt_use));
     327                dprintf(("IPHLPAPI:   rt_ifp      0x%p", rtentry->rt_ifp));
     328                //dprintf(("IPHLPAPI:     if_name   %s", rtentry->rt_ifp->if_name));
     329                dprintf(("IPHLPAPI:   metric1     %d", rtentry->metric1));
     330                dprintf(("IPHLPAPI:   metric2     %d", rtentry->metric2));
     331                dprintf(("IPHLPAPI:   metric3     %d", rtentry->metric3));
     332                dprintf(("IPHLPAPI:   metric4     %d", rtentry->metric4));
     333            }
     334#endif
    307335            // only take default gateways for this interface
     336#if 1
     337            // rtentry->rt_ifp is (always?) a high address (0xFxxxxxxx) and for
     338            // some reason reading it causes an access violation on some systems
     339            // while works great on other systems. I don't know why. Luckily
     340            // (luckily???), the definition of struct rtentries in headers is
     341            // wrong -- each entry in the rtentries::rttable array is
     342            // additionally followed by an ASCIIZ string containing the
     343            // interface name. And the interface name is what we need. Owse.
     344            char *if_name = (char *)(rtentry + 1);
     345            dprintf(("IPHLPAPI:   if_name     %s", if_name));
     346
     347            if (strcmp(if_name, iShortName) == 0 &&
     348#else
    308349            if (strcmp(rtentry->rt_ifp->if_name, iShortName) == 0 &&
     350#endif
    309351                ((struct sockaddr_in *)(&rtentry->rt_dst))->sin_addr.s_addr == 0)
    310352            {
     
    331373            }
    332374
    333             // For some strange reason, the definition of struct rtentries
    334             // is wrong. Each entry in the rtentries::rttable array is followed
    335             // by the interface name. Compensate for that.
     375            // Compensate for the interface name following the rtentry
    336376            ++rtentry;
    337377            rtentry = (struct rtentry *)
Note: See TracChangeset for help on using the changeset viewer.