Changeset 10066 for trunk/src/iphlpapi/iphlpapi.cpp
- Timestamp:
- May 5, 2003, 5:10:57 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/iphlpapi/iphlpapi.cpp
r9329 r10066 1 /* $Id: iphlpapi.cpp,v 1.1 2 2002-10-07 11:02:03sandervl Exp $ */1 /* $Id: iphlpapi.cpp,v 1.13 2003-05-05 15:10:56 sandervl Exp $ */ 2 2 /* 3 3 * IPHLPAPI library … … 21 21 #include <string.h> 22 22 #include "iphlpapi.h" 23 #include <winnls.h> 23 24 24 25 #define BSD_SELECT 1 … … 84 85 ****************************************************************************/ 85 86 86 static PIP_ADAPTER_INFO pipAdapter = NULL; 87 87 static PIP_ADAPTER_INFO pipAdapter = NULL; 88 static PMIB_IFTABLE pmibTable = NULL; 89 static PMIB_IPADDRTABLE pmipaddrTable = NULL; 88 90 89 91 //****************************************************************************** … … 115 117 PIP_ADAPTER_INFO oldAdapter = NULL,topAdapter = NULL; 116 118 struct sockaddr_in * sin; 117 struct ifmib ifmibget;118 119 int rc,i; 119 120 char *buffer=NULL,*buffer2=NULL; 120 121 struct ifnet *pifnet; 121 short int cInterfaces; 122 struct ifmib ifmibget; 123 int cInterfaces; 122 124 #ifndef TCPV40HDRS 123 125 struct ortentry *r; … … 158 160 cInterfaces = *(short int*)buffer; 159 161 dprintf(("IPHLPAPI Call returned %d interfaces\n", cInterfaces)); 162 163 pmibTable = (PMIB_IFTABLE)malloc(cInterfaces*sizeof(MIB_IFTABLE)); 164 memset(pmibTable, 0, cInterfaces*sizeof(MIB_IFTABLE)); 165 pmibTable->dwNumEntries = cInterfaces; 166 167 pmipaddrTable = (PMIB_IPADDRTABLE)malloc(cInterfaces*sizeof(MIB_IPADDRTABLE)); 168 memset(pmipaddrTable, 0, cInterfaces*sizeof(MIB_IPADDRTABLE)); 169 pmipaddrTable->dwNumEntries = cInterfaces; 160 170 161 171 for (int currentInterface = 0; currentInterface < cInterfaces; currentInterface++) … … 205 215 pipAdapter->Type = ifmibget.iftable[i].ifType; // Careful with this (?) 206 216 pipAdapter->DhcpEnabled = 0; // Also a question 207 217 218 MultiByteToWideChar(CP_ACP, 0, iShortName, strlen(iShortName), 219 pmibTable->table[currentInterface].wszName, 220 MAX_INTERFACE_NAME_LEN); 221 222 pmibTable->table[currentInterface].dwIndex = ifmibget.iftable[i].ifIndex; 223 pmibTable->table[currentInterface].dwType = ifmibget.iftable[i].ifType; /* type of the interface */ 224 pmibTable->table[currentInterface].dwMtu = ifmibget.iftable[i].ifMtu; /* MTU of the interface */ 225 pmibTable->table[currentInterface].dwSpeed = ifmibget.iftable[i].ifSpeed; 226 227 pmibTable->table[currentInterface].dwPhysAddrLen = 0; //?? 228 memcpy(pmibTable->table[currentInterface].bPhysAddr, ifmibget.iftable[i].ifPhysAddr, sizeof(ifmibget.iftable[i].ifPhysAddr)); 229 230 pmibTable->table[currentInterface].dwAdminStatus = ifmibget.iftable[i].ifOperStatus; 231 pmibTable->table[currentInterface].dwOperStatus = (ifmibget.iftable[i].ifOperStatus == IFF_UP) ? MIB_IF_OPER_STATUS_OPERATIONAL : MIB_IF_OPER_STATUS_NON_OPERATIONAL; 232 233 pmibTable->table[currentInterface].dwLastChange = ifmibget.iftable[i].ifLastChange; 234 pmibTable->table[currentInterface].dwInOctets = ifmibget.iftable[i].ifInOctets; 235 pmibTable->table[currentInterface].dwInUcastPkts = ifmibget.iftable[i].ifInUcastPkts; 236 pmibTable->table[currentInterface].dwInNUcastPkts = ifmibget.iftable[i].ifInNUcastPkts; 237 pmibTable->table[currentInterface].dwInDiscards = ifmibget.iftable[i].ifInDiscards; 238 pmibTable->table[currentInterface].dwInErrors = ifmibget.iftable[i].ifInErrors; 239 pmibTable->table[currentInterface].dwInUnknownProtos = ifmibget.iftable[i].ifInUnknownProtos; 240 pmibTable->table[currentInterface].dwOutOctets = ifmibget.iftable[i].ifOutOctets; 241 pmibTable->table[currentInterface].dwOutUcastPkts = ifmibget.iftable[i].ifOutUcastPkts; 242 pmibTable->table[currentInterface].dwOutNUcastPkts = ifmibget.iftable[i].ifOutNUcastPkts; 243 pmibTable->table[currentInterface].dwOutDiscards = ifmibget.iftable[i].ifOutDiscards; 244 pmibTable->table[currentInterface].dwOutErrors = ifmibget.iftable[i].ifOutErrors; 245 // pmibTable->table[currentInterface].dwOutQLen 246 247 pmibTable->table[currentInterface].dwDescrLen = strlen(ifmibget.iftable[i].ifDescr); 248 strncpy((char *)pmibTable->table[currentInterface].bDescr, ifmibget.iftable[i].ifDescr, sizeof(pmibTable->table[currentInterface].bDescr)); 249 250 251 pmipaddrTable->table[currentInterface].dwAddr = ifInfo->IPAddress; 252 pmipaddrTable->table[currentInterface].dwMask = ifInfo->netmask; 253 pmipaddrTable->table[currentInterface].dwBCastAddr = 0; //?? 254 pmipaddrTable->table[currentInterface].dwIndex = ifmibget.iftable[i].ifIndex; 255 256 ; /* MTU of the interface */ 257 258 259 208 260 // TODO: Adapter may support multiple IP addrs 209 261 IP_ADDR_STRING iasAdapterIP; … … 490 542 ); 491 543 // SIOCDIFADDR 544 545 //****************************************************************************** 546 //****************************************************************************** 547 DWORD WIN32API GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, 548 BOOL bOrder) 549 { 550 DWORD buflen; 551 DWORD rc; 552 553 dprintf(("GetIpAddrTable %x %x %d", pIpAddrTable, pdwSize, bOrder)); 554 555 if(pdwSize == NULL) { 556 rc = ERROR_INVALID_PARAMETER; 557 goto end; 558 } 559 560 if(pmipaddrTable == NULL) 561 { 562 // gather the information and save it 563 i_initializeAdapterInformation(); 564 } 565 if(pmipaddrTable == NULL) 566 return ERROR_NO_DATA; 567 568 569 buflen = sizeof(MIB_IPADDRTABLE) - sizeof(MIB_IPADDRROW); 570 buflen+= pmibTable->dwNumEntries*sizeof(MIB_IPADDRROW); 571 572 if(buflen > *pdwSize) { 573 *pdwSize = buflen; 574 rc = ERROR_BUFFER_OVERFLOW; 575 goto end; 576 } 577 rc = ERROR_SUCCESS; 578 579 memcpy(pIpAddrTable, pmipaddrTable, buflen); 580 581 end: 582 dprintf(("GetIpAddrTable returned %d", rc)); 583 return rc; 584 } 585 //****************************************************************************** 586 //****************************************************************************** 587 DWORD WIN32API GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder) 588 { 589 DWORD buflen; 590 DWORD rc; 591 592 dprintf(("GetIfTable %x %x %d", pIfTable, pdwSize, bOrder)); 593 594 if(pdwSize == NULL) { 595 rc = ERROR_INVALID_PARAMETER; 596 goto end; 597 } 598 599 if(pmibTable == NULL) 600 { 601 // gather the information and save it 602 i_initializeAdapterInformation(); 603 } 604 if(pmibTable == NULL) 605 return ERROR_NO_DATA; 606 607 608 buflen = sizeof(MIB_IFTABLE) - sizeof(MIB_IFROW); 609 buflen+= pmibTable->dwNumEntries*sizeof(MIB_IFROW); 610 611 if(buflen > *pdwSize) { 612 *pdwSize = buflen; 613 rc = ERROR_BUFFER_OVERFLOW; 614 goto end; 615 } 616 617 memcpy(pIfTable, pmibTable, buflen); 618 619 rc = ERROR_SUCCESS; 620 end: 621 dprintf(("GetIfTable returned %d", rc)); 622 return rc; 623 } 624 //****************************************************************************** 625 //****************************************************************************** 626 DWORD WIN32API GetFriendlyIfIndex(DWORD IfIndex) 627 { 628 dprintf(("GetFriendlyIfIndex %d; returns the same index", IfIndex)); 629 return IfIndex; 630 } 631 //****************************************************************************** 632 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.