src/SeeDll/Packet32.c
/*!
  \brief Retrieve the list of available network adapters and their description.
  \param pStr User allocated string that will be filled with the names of the adapters.
  \param BufferSize Length of the buffer pointed by pStr. If the function fails, this variable contains the 
         number of bytes that are needed to contain the adapter list.
  \return If the function succeeds, the return value is nonzero. If the return value is zero, BufferSize contains 
          the number of bytes that are needed to contain the adapter list.

  Usually, this is the first function that should be used to communicate with the driver.
  It returns the names of the adapters installed on the system <B>and supported by WinPcap</B>. 
  After the names of the adapters, pStr contains a string that describes each of them.

  After a call to PacketGetAdapterNames pStr contains, in succession:
  - a variable number of ASCII strings, each with the names of an adapter, separated by a "\0"
  - a double "\0"
  - a number of ASCII strings, each with the description of an adapter, separated by a "\0". The number 
   of descriptions is the same of the one of names. The first description corresponds to the first name, and
   so on.
  - a double "\0". 
*/
\brief Retrieve the list of available network adapters and their description.
\param pStr User allocated string that will be filled with the names of the adapters.
\param BufferSize Length of the buffer pointed by pStr. If the function fails, this variable contains the
number of bytes that are needed to contain the adapter list.
\return If the function succeeds, the return value is nonzero. If the return value is zero, BufferSize contains
the number of bytes that are needed to contain the adapter list.

Usually, this is the first function that should be used to communicate with the driver.
It returns the names of the adapters installed on the system and supported by WinPcap.
After the names of the adapters, pStr contains a string that describes each of them.


\ brief Retrieve the list of available network adapters and their description . \ param pStr User allocated string that will be filled with the names of the adapters . \ param BufferSize Length of the buffer pointed by pStr . If the function fails this variable contains the number of bytes that are needed to contain the adapter list . \ return If the function succeeds the return value is nonzero . If the return value is zero BufferSize contains the number of bytes that are needed to contain the adapter list . Usually this is the first function that should be used to communicate with the driver . It returns the names of the adapters installed on the system and supported by WinPcap . After the names of the adapters pStr contains a string that describes each of them .
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG  BufferSize)
{
	PADAPTER_INFO	TAdInfo;
	ULONG	SizeNeeded = 1;
	ULONG	SizeNames = 1;
	ULONG	SizeDesc;
	ULONG	OffDescriptions;
	ODSEx("PacketGetAdapterNames: BufferSize=%d\n", *BufferSize);
	PacketPopulateAdaptersInfoList();
	WaitForSingleObject(AdaptersInfoMutex, INFINITE);
	if(!AdaptersInfoList) 
	{
		ReleaseMutex(AdaptersInfoMutex);
		*BufferSize = 0;
		return FALSE;		
	}
	for(TAdInfo = AdaptersInfoList; TAdInfo != NULL; TAdInfo = TAdInfo->Next)
	{
		if(TAdInfo->Flags != INFO_FLAG_DONT_EXPORT)
		{
			SizeNeeded += (int)strlen(TAdInfo->Name) + (int)strlen(TAdInfo->Description) + 2;
			SizeNames += (int)strlen(TAdInfo->Name) + 1;
		}
	}
	if(SizeNeeded + 2 >= *BufferSize || pStr == NULL)
	{
		ReleaseMutex(AdaptersInfoMutex);
		ODS("PacketGetAdapterNames: input buffer too small\n");
		*BufferSize = SizeNeeded + 4;  
		return FALSE;
	}
	OffDescriptions = SizeNames;
	for(TAdInfo = AdaptersInfoList, SizeNames = 0, SizeDesc = 0; TAdInfo != NULL; TAdInfo = TAdInfo->Next)
	{
		if(TAdInfo->Flags != INFO_FLAG_DONT_EXPORT)
		{
			strcpy(((PCHAR)pStr) + SizeNames, TAdInfo->Name);
			strcpy(((PCHAR)pStr) + OffDescriptions + SizeDesc, TAdInfo->Description);
			SizeNames += (int)strlen(TAdInfo->Name) + 1;
			SizeDesc += (int)strlen(TAdInfo->Description) + 1;
		}
	}
	((PCHAR)pStr)[SizeNames] = 0;
	((PCHAR)pStr)[SizeNeeded] = 0;
	ReleaseMutex(AdaptersInfoMutex);
	return TRUE;
}
BOOLEAN PacketGetAdapterNames ( PTSTR pStr , PULONG BufferSize ) { PADAPTER_INFO TAdInfo ; ULONG SizeNeeded = 1 ; ULONG SizeNames = 1 ; ULONG SizeDesc ; ULONG OffDescriptions ; ODSEx ( " \n " , * BufferSize ) ; PacketPopulateAdaptersInfoList ( ) ; WaitForSingleObject ( AdaptersInfoMutex , INFINITE ) ; if ( ! AdaptersInfoList ) { ReleaseMutex ( AdaptersInfoMutex ) ; * BufferSize = 0 ; return FALSE ; } for ( TAdInfo = AdaptersInfoList ; TAdInfo != NULL ; TAdInfo = TAdInfo -> Next ) { if ( TAdInfo -> Flags != INFO_FLAG_DONT_EXPORT ) { SizeNeeded += ( int ) strlen ( TAdInfo -> Name ) + ( int ) strlen ( TAdInfo -> Description ) + 2 ; SizeNames += ( int ) strlen ( TAdInfo -> Name ) + 1 ; } } if ( SizeNeeded + 2 >= * BufferSize || pStr == NULL ) { ReleaseMutex ( AdaptersInfoMutex ) ; ODS ( " \n " ) ; * BufferSize = SizeNeeded + 4 ; return FALSE ; } OffDescriptions = SizeNames ; for ( TAdInfo = AdaptersInfoList , SizeNames = 0 , SizeDesc = 0 ; TAdInfo != NULL ; TAdInfo = TAdInfo -> Next ) { if ( TAdInfo -> Flags != INFO_FLAG_DONT_EXPORT ) { strcpy ( ( ( PCHAR ) pStr ) + SizeNames , TAdInfo -> Name ) ; strcpy ( ( ( PCHAR ) pStr ) + OffDescriptions + SizeDesc , TAdInfo -> Description ) ; SizeNames += ( int ) strlen ( TAdInfo -> Name ) + 1 ; SizeDesc += ( int ) strlen ( TAdInfo -> Description ) + 1 ; } } ( ( PCHAR ) pStr ) [ SizeNames ] = 0 ; ( ( PCHAR ) pStr ) [ SizeNeeded ] = 0 ; ReleaseMutex ( AdaptersInfoMutex ) ; return TRUE ; }
\brief Retrieve the list of available network adapters and their description.
\ brief Retrieve the list of available network adapters and their description .
//
 // Create the adapter information list
 //
 // No adapters to return
 // 
 // First scan of the list to calculate the offsets and check the sizes
 //
 // Update the size variables
 // Check that we don't overflow the buffer.
 // Note: 2 is the number of additional separators needed inside the list
 // Report the required size
 // 
 // Second scan of the list to copy the information
 //
 // Copy the data
 // Update the size variables
 // Separate the two lists
 // End the list with a further \0
