|
I just
knew you were going to ask that question. ;>)
I omitted
that part of the code so it wouldn't be confusing and most people don't care
about Windows 95/98.
Since you
do, here is the version that will work on any version of windows supported by
WinPCap.
int
main(int argc, char* argv[])
{ DWORD dwVersion;
DWORD dwWindowsMajorVersion; unsigned int i; long lRC; // Long return code. WCHAR AdapterName[8192]; // string that contains a list of the network adapters WCHAR *temp, *temp1; char AdapterList[MAX_NUM_ADAPTERS][1024]; char TempAsciiString[8192];
//ascii strings (win95) char AdapterNamea[8192]; // string that contains a list of the network adapters char *tempa,*temp1a; unsigned int AdapterNum = 0; ULONG AdapterLength; memset(AdapterList, 0, (MAX_NUM_ADAPTERS * 1024)
);
memset(AdapterName, 0, sizeof(AdapterName) ); memset(AdapterNamea, 0, sizeof(AdapterNamea) ); memset(TempAsciiString, 0, sizeof(TempAsciiString) ); //
obtain the name of the adapters installed on this
machine
AdapterLength=4096; printf("\n===============================================\n");
printf("Valid Packet Sniffing Adapters:\n"); i=0;
// the data returned by PacketGetAdapterNames is different in Win95/98 // and WinNT/2000/XP. // We have to check the OS on which we are running dwVersion=GetVersion(); dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4)) { // Windows NT/2000/XP if(PacketGetAdapterNames((char *)AdapterName, &AdapterLength) == FALSE) { printf("Error: Unable to retrieve the list of the adapters!\n"); exit(-1); } // The string returned is a multi-byte string. temp = AdapterName; temp1 = AdapterName; while (true) { if( (*temp1 == '\0') && (*(temp1+1) == '\0') ) { // We're at the end of the string. break; } if (*(temp1+1) == '\0') { // Temp1 points to the end of the string. nRC = WideCharToMultiByte(CP_ACP, 0, temp, -1, TempAsciiString, sizeof(TempAsciiString), 0, 0); if (nRC > 0) { memcpy(AdapterList[i], TempAsciiString, (temp1 - temp)+1); } temp = temp1+2; i++; } temp1++; } AdapterNum=i; for (i = 0; i < AdapterNum; i++) { printf("%d- %s\n", i+1, AdapterList[i]); } printf("\n"); } else { //windows 95/98 if(PacketGetAdapterNames(AdapterNamea,&AdapterLength)==FALSE) { printf("Error: Unable to retrieve the list of the adapters!\n"); exit(-1); } tempa = AdapterNamea; temp1a = AdapterNamea; while (true) { if( (*temp1a == '\0') && (*(temp1a+1) == '\0') ) { // We're at the end of the string. break; } if (*(temp1a+1) == '\0') { // Temp1 points to the end of the string. memcpy(AdapterList[i], tempa, (temp1a - tempa)+1); tempa = temp1a+2; i++; } temp1a++; } AdapterNum=i; for (i = 0; i < AdapterNum; i++) { printf("%d- %s\n", i+1, AdapterList[i]); } printf("\n"); } } Thank you,
|
- [WinPcap-users] retreiving adapter info Annie Deroo
- Re: [WinPcap-users] retreiving adapter info Selcuk Cevher
- RE: [WinPcap-users] retreiving adapter info David Barnish
- Re: [WinPcap-users] retreiving adapter info Annie Deroo
- Re: [WinPcap-users] retreiving adapter info Daniel Frimerman
- Re: [WinPcap-users] retreiving adapter info David Barnish
- Re: [WinPcap-users] retreiving adapter info Annie Deroo
