Ignore:
Timestamp:
May 5, 2003, 5:10:57 PM (22 years ago)
Author:
sandervl
Message:

Implemented GetIpAddrTable, GetIfTable & GetFriendlyIfIndex

File:
1 edited

Legend:

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

    r9329 r10066  
    1 /* $Id: iphlpapi.cpp,v 1.12 2002-10-07 11:02:03 sandervl Exp $ */
     1/* $Id: iphlpapi.cpp,v 1.13 2003-05-05 15:10:56 sandervl Exp $ */
    22/*
    33 *      IPHLPAPI library
     
    2121#include <string.h>
    2222#include "iphlpapi.h"
     23#include <winnls.h>
    2324
    2425#define BSD_SELECT 1
     
    8485 ****************************************************************************/
    8586
    86 static PIP_ADAPTER_INFO pipAdapter = NULL;
    87 
     87static PIP_ADAPTER_INFO pipAdapter    = NULL;
     88static PMIB_IFTABLE     pmibTable     = NULL;
     89static PMIB_IPADDRTABLE pmipaddrTable = NULL;
    8890
    8991//******************************************************************************
     
    115117  PIP_ADAPTER_INFO oldAdapter = NULL,topAdapter = NULL;
    116118  struct sockaddr_in * sin;
    117   struct ifmib ifmibget;
    118119  int rc,i;
    119120  char *buffer=NULL,*buffer2=NULL;
    120121  struct ifnet *pifnet;
    121   short int cInterfaces;
     122  struct ifmib  ifmibget;
     123  int cInterfaces;
    122124#ifndef TCPV40HDRS
    123125  struct ortentry *r;
     
    158160  cInterfaces = *(short int*)buffer;
    159161  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;
    160170
    161171  for (int currentInterface = 0; currentInterface < cInterfaces; currentInterface++)
     
    205215    pipAdapter->Type = ifmibget.iftable[i].ifType; // Careful with this (?)
    206216    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
    208260    // TODO: Adapter may support multiple IP addrs
    209261    IP_ADDR_STRING iasAdapterIP;
     
    490542                     );
    491543// SIOCDIFADDR
     544
     545//******************************************************************************
     546//******************************************************************************
     547DWORD 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
     581end:
     582    dprintf(("GetIpAddrTable returned %d", rc));
     583    return rc;
     584}
     585//******************************************************************************
     586//******************************************************************************
     587DWORD 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;
     620end:
     621    dprintf(("GetIfTable returned %d", rc));
     622    return rc;
     623}
     624//******************************************************************************
     625//******************************************************************************
     626DWORD 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.