Click to See Complete Forum and Search --> : GetAdaptersAddresses and IP
ehmano
May 22nd, 2004, 04:23 AM
i m using GetAdaptersAddresses to retrieve info from my interfaces but i can not figure out how to get the corresponding IP address !!
Wher should i look into IP_ADAPTER_ADDRESSES to get this **** IP and the subnet and gateway,
it must be possible ??
Guido Niewerth
May 22nd, 2004, 10:20 AM
Have a look at GetAdaptersInfo. GetAdaptersInfo fills a buffer with a linked list of IP_ADAPTER_INFO structures, the only thing you have to do is provide enough space and walk the list. I´m not sure if you can determine the subnet mask this way.
Hope this helps,
Guido
ehmano
May 22nd, 2004, 12:41 PM
i already tried that one and it doesn't work, because i'm on XP.
This function gives bugs with XP and server 2003.
thanks for ur reply anyway.
Andreas Masur
May 22nd, 2004, 06:04 PM
[Moved thread]
Jim Mcpherson
May 24th, 2004, 02:17 PM
//code
DWORD GetNetworkLanIndex()
{
PIP_ADAPTER_INFO pAdapterInfo = NULL;
PIP_ADAPTER_INFO pOriginalPtr;
ULONG ulSizeAdapterInfo = 0;
DWORD dwStatus=0;
DWORD dwLanIndex=0;
// Find out how big our buffer needs to be to hold
// the data
dwStatus = GetAdaptersInfo(pAdapterInfo, &ulSizeAdapterInfo);
if(dwStatus == ERROR_BUFFER_OVERFLOW)
{
// Allocate a buffer of the appropriate size
if(!(pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulSizeAdapterInfo)))
{
// Insufficient memory
return 0;
}
// Obtain the Adapter Info
dwStatus = GetAdaptersInfo(pAdapterInfo, &ulSizeAdapterInfo);
}
if(dwStatus != ERROR_SUCCESS)
{
if(pAdapterInfo)
free(pAdapterInfo);
return 0;
}
pOriginalPtr = pAdapterInfo;
if(pOriginalPtr == NULL)
{
//printf("\n No Interfaces Present.\n");
if(pAdapterInfo)
free(pAdapterInfo);
return 0;
}
// Step through the adapter list
while (pOriginalPtr != NULL)
{
// Print the Ip Addresses
//printf(" \n\n\t IpAddressList:: ");
PIP_ADDR_STRING pAddressList =
&(pOriginalPtr->IpAddressList);
dwLanIndex = pOriginalPtr->Index;
//if(dwLanIndex>0)
// break;
do
{
//printf("\n\t IpAddress = %hs", pAddressList->IpAddress.String);
pAddressList = pAddressList->Next;
} while (pAddressList != NULL);
// And so on with other members of the Adapter info structure…..
pOriginalPtr = pOriginalPtr->Next;
} // while(pOriginalPtr!=NULL){
if(pAdapterInfo)
free(pAdapterInfo);
return dwLanIndex;
}
//code
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.