Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 11th, 2008, 11:35 AM
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









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.