Thread: GetAdapterName
View Single Post
  #1 (permalink)  
Old November 11th, 2008, 11:35 AM
Chizl Chizl is offline
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default GetAdapterName

I'm getting the adapter name using the GetAdapterName API from the obj->Description property since the obj->AdapterName property seems to always have a GUID in it instead of the name. However, I fell apon a laptop that the description has more than just the name.

So here is my issue and keep in mind I'm writing a monitoring utility for not only my applications on the machine, but for the computer as well.

I'm using GetBestInterface API to pull the IP address. From there I query to get the NIC Name for that IP, just in case they have more than one NIC. With that NIC I query perfmon for Bytes Received and Bytes Sent so I must have the NIC Name.

Is there a better way to get the NIC name that from the Description of the GetAdapterName API?

This is the code I use:
bool CWSock::GetAdapterName(string szIP, string* szNICName)
{
    PIP_ADAPTER_INFO pCurAdapt;
    IP_ADAPTER_INFO buffer[10];
    ULONG len = sizeof(IP_ADAPTER_INFO)*10;
    DWORD res;
    bool bPassed = false;

    res = GetAdaptersInfo(buffer, &len); // fill buffer by structures

    if (res == ERROR_SUCCESS)
    {
        pCurAdapt = &buffer[0]; // get pointer to the first structure

        do {
            char pstr[1024] = {0};

            PIP_ADDR_STRING pCurIP = &(pCurAdapt->IpAddressList);
            sprintf(pstr, pCurIP->IpAddress.String);

            if(strcmp(szIP.c_str(), pstr)==0)
            {
                *szNICName = pCurAdapt->Description;
                bPassed = true;
                break;
            }
        } while ((pCurAdapt = pCurAdapt->Next) != NULL); // pCurAdapt->Next is NULL
    }

    return bPassed;
}


--
Chizl
Reply With Quote