Ignore:
Timestamp:
Aug 13, 2010, 2:37:57 PM (15 years ago)
Author:
dmik
Message:

iphlpapi: Fix the byte order in the reported interface mask and report the actual broadcast address instead of 0-s.

File:
1 edited

Legend:

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

    r21411 r21412  
    104104                        (char)(*(((char*)&data) + 2)),
    105105                        (char)(*(((char*)&data) + 3)));
    106 }
    107 
    108 void stringNetmask(char* dst,u_long data)
    109 {
    110    sprintf(dst,"%u.%u.%u.%u",
    111                         (char)(*(((char*)&data) + 3)),
    112                         (char)(*(((char*)&data) + 2)),
    113                         (char)(*(((char*)&data) + 1)),
    114                         (char)data);
    115106}
    116107
     
    251242
    252243    pmibTable->table[currentInterface].dwDescrLen = strlen(ifmibget.iftable[i].ifDescr);
    253     strncpy((char *)pmibTable->table[currentInterface].bDescr, iShortName, strlen(iShortName));
    254 //    strncpy((char *)pmibTable->table[currentInterface].bDescr, ifmibget.iftable[i].ifDescr, sizeof(pmibTable->table[currentInterface].bDescr));
     244    strncpy((char *)pmibTable->table[currentInterface].bDescr, ifmibget.iftable[i].ifDescr, sizeof(pmibTable->table[currentInterface].bDescr));
    255245
    256246
    257247    pmipaddrTable->table[currentInterface].dwAddr = ifInfo->IPAddress;
    258     pmipaddrTable->table[currentInterface].dwMask = ifInfo->netmask;
    259     pmipaddrTable->table[currentInterface].dwBCastAddr = 0; //??
     248    // mask is in network byte order for some reason
     249    pmipaddrTable->table[currentInterface].dwMask = ntohl(ifInfo->netmask);
     250    pmipaddrTable->table[currentInterface].dwBCastAddr = ifInfo->broadcastAddress;
    260251    pmipaddrTable->table[currentInterface].dwIndex = ifmibget.iftable[i].ifIndex;
    261252
    262 ;  /* MTU of the interface   */
     253    /* MTU of the interface   */
    263254
    264255
     
    268259    iasAdapterIP.Next = NULL;
    269260    stringIPAddress((char*)&iasAdapterIP.IpAddress,ifInfo->IPAddress);
    270     stringNetmask((char*)&iasAdapterIP.IpMask,ifInfo->netmask);
     261    stringIPAddress((char*)&iasAdapterIP.IpMask,ntohl(ifInfo->netmask));
    271262    iasAdapterIP.Context = 0;
    272263
Note: See TracChangeset for help on using the changeset viewer.