Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by Adam
Wed, 22 Feb 2006 00:32
Get network card info
Author: Adam
Date: Wed, 22 Feb 2006 00:32
Date: Wed, 22 Feb 2006 00:32
5 lines
953 bytes
953 bytes
In C++ , how do I get info of network card? thanks -- Borland�������� http://www.BorlandBBS.cn
Re: Get network card info
Author: Mark Jacobs
Date: Wed, 22 Feb 2006 13:31
Date: Wed, 22 Feb 2006 13:31
25 lines
1728 bytes
1728 bytes
Adam wrote:
> In C++ , how do I get info of network card? thanks
AnsiString mjgetnicinfo()
{
IP_ADAPTER_INFO AdapterInfo[16]; AnsiString retv="";
unsigned int ii; DWORD dwBufLen,dwStatus;
dwBufLen=sizeof(AdapterInfo); dwStatus=GetAdaptersInfo(AdapterInfo,&dwBufLen);
if (dwStatus!=ERROR_SUCCESS) return "**Could not Obtain NIC Info";
PIP_ADAPTER_INFO pAdapterInfo=AdapterInfo;
do
{
retv+="Name :"+AnsiString(pAdapterInfo->AdapterName)+"\r\nDescription :"+
AnsiString(pAdapterInfo->Description)+"\r\nMAC :";
for (ii=0;ii<pAdapterInfo->AddressLength;++ii)
retv+=IntToHex(pAdapterInfo->Address[ii],2)+" ";
retv+="\r\n"; pAdapterInfo=pAdapterInfo->Next;
}
while (pAdapterInfo);
return retv;
}
--
Mark Jacobs
http://www.dkcomputing.co.uk
Re: Get network card info
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Feb 2006 22:58
Date: Wed, 22 Feb 2006 22:58
64 lines
2844 bytes
2844 bytes
"Mark Jacobs" <markj@critical.co.uk> wrote in message
news:43fc678d$1@newsgroups.borland.com...
> IP_ADAPTER_INFO AdapterInfo[16];
I would suggest dynamically allocating the array instead, ie:
#include <Iphlpapi.h>
AnsiString mjgetnicinfo()
{
PIP_ADAPTER_INFO *Adapters = NULL;
ULONG ulBufLen = 0;
AnsiString retv;
if( GetAdaptersInfo(NULL, &uiBufLen) == ERROR_BUFFER_OVERFLOW )
{
Adapters = (PIP_ADAPTER_INFO) LocalAlloc(LMEM_FIXED, uiBufLen);
if( Adapters )
{
try
{
if( GetAdaptersInfo(Adapters, &uiBufLen) ==
ERROR_SUCCESS )
{
PIP_ADAPTER_INFO pAdapter = Adapters;
do
{
AnsiString info;
info.sprintf("Name: %s\r\nDescription:
%s\r\nMAC: ",
pAdapter->AdapterName,
pAdapterInfo->Description);
for(unsigned int ii = 0; ii <
pAdapter->AddressLength; ++ii)
info += IntToHex(pAdapter->Address[ii], 2) +
":";
info += "\r\n";
retv += info;
pAdapter = pAdapter->Next;
}
while( pAdapter );
}
else
retv = "**Could not Obtain NIC Info";
}
__finally {
LocalFree(Adapters);
}
}
else
retv = "**Could not Allocate Memory for NIC Info";
}
else
retv = "**Could not Calculate NIC Info";
return retv;
}
Gambit
Re: Get network card info
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Feb 2006 22:59
Date: Wed, 22 Feb 2006 22:59
11 lines
1094 bytes
1094 bytes
"Adam" <support@borlandBBS.cn> wrote in message
news:43fbb113@newsgroups.borland.com...
> In C++ , how do I get info of network card?
GetAdaptersInfo()
http://msdn.microsoft.com/library/en-us/iphlp/iphlp/getadaptersinfo.asp
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads