Thank u very much! it works like a dream.
----- Original Message -----
Sent: Tuesday, July 01, 2003 3:54 PM
Subject: RE: [WinPcap-users] retreiving adapter info

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,

David Barnish
Senior Software Engineer
Research And Development
[EMAIL PROTECTED]

Spanlink Communications
7125 Northland Terrace, Suite 100
Brooklyn Park, Minnesota 55428
(763) 971-2000
 

-----Original Message-----
From: Annie Deroo [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 01, 2003 8:43 AM
To: [EMAIL PROTECTED]
Subject: Re: [WinPcap-users] retreiving adapter info

It works, but I have a question: can this code also be used under Win95 or 98? I know there is a difference between them and NT or XP. And what do I have to change to make it work under both systems?
 
Thank U
----- Original Message -----
Sent: Monday, June 30, 2003 4:03 PM
Subject: RE: [WinPcap-users] retreiving adapter info

Try this...
 
 unsigned int i;
 int nRC;
 WCHAR AdapterName[8192]; // string that contains a list of the network adapters
 WCHAR *temp, *temp1;
 char  AdapterList[MAX_NUM_ADAPTERS][1024];
 char  TempAsciiString[8192];
 unsigned int AdapterNum = 0;
 ULONG  AdapterLength;
 
 memset(AdapterList, 0, (MAX_NUM_ADAPTERS * 1024) );
 memset(AdapterName, 0, sizeof(AdapterName) );
 memset(TempAsciiString, 0, sizeof(TempAsciiString) );
 
 // obtain the name of the adapters installed on this machine
 AdapterLength=4096;
 
 i=0;
 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 on WinNT or later versions of Windows.
 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");
David Barnish
 
 


-----Original Message-----
From: Annie Deroo [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 29, 2003 8:21 AM
To: [EMAIL PROTECTED]
Subject: [WinPcap-users] retreiving adapter info

How can I get a list of my adapters? I know the function PacketGetAdapterNames gives me all the adapters on my computers, but how do I show information about them in a Visual C++ program? Functions like wprintf(L"\n%d- %s\n",i+1,AdapterList[i]) (output = 7) and printf("\n%d- %s\n",i+1,AdapterList[i]) (error when running) can't be used to put a CString in a list or in a messagebox! The compiler says: left of '.SymbolicLink' must have class/struct/union type, when I use the SymbolicLink part of the adapters. In my program I want to show info about the available adapters in a list and let the user select one. I'm sure this is done before in Visual C++, so if somebody knows how I could do that or knows where I can find code that does that, let me know. Thank U

Reply via email to