src/SeeDll/Packet32.c
/*! 
  \brief Opens an adapter.
  \param AdapterName A string containing the name of the device to open. 
   Use the PacketGetAdapterNames() function to retrieve the list of available devices.
  \return If the function succeeds, the return value is the pointer to a properly initialized ADAPTER object,
   otherwise the return value is NULL.
*/
\brief Opens an adapter.
\param AdapterName A string containing the name of the device to open.
Use the PacketGetAdapterNames() function to retrieve the list of available devices.
\return If the function succeeds, the return value is the pointer to a properly initialized ADAPTER object,
otherwise the return value is NULL.
\ brief Opens an adapter . \ param AdapterName A string containing the name of the device to open . Use the PacketGetAdapterNames () function to retrieve the list of available devices . \ return If the function succeeds the return value is the pointer to a properly initialized ADAPTER object otherwise the return value is NULL .
LPADAPTER PacketOpenAdapter(PCHAR AdapterName)
{
    LPADAPTER lpAdapter;
	WCHAR *AdapterNameU;
	SC_HANDLE svcHandle = NULL;
	PCHAR AdapterNameA = NULL;
#ifndef _WINNT4
	PADAPTER_INFO TAdInfo;
#endif 
	ODSEx("PacketOpenAdapter: trying to open the adapter=%s\n",AdapterName)
	if(AdapterName[1]!=0)
	{ 
		AdapterNameU = SChar2WChar(AdapterName);
		AdapterNameA = AdapterName;
		AdapterName = (PCHAR)AdapterNameU;
	} 
	else 
	{	
		AdapterNameU = NULL;
		AdapterNameA = WChar2SChar((PWCHAR)AdapterName);
	}
#ifndef _WINNT4
	WaitForSingleObject(AdaptersInfoMutex, INFINITE);
	TAdInfo = PacketFindAdInfo(AdapterNameA);
	if(TAdInfo == NULL)
	{
		PacketUpdateAdInfo(AdapterNameA);
		TAdInfo = PacketFindAdInfo(AdapterNameA);
		if(TAdInfo == NULL)
		{
			lpAdapter = PacketOpenAdapterDAG(AdapterNameA, TRUE);
			if (AdapterNameU != NULL) 
				GlobalFreePtr(AdapterNameU);
			else 
				GlobalFreePtr(AdapterNameA);
			ReleaseMutex(AdaptersInfoMutex);
			if (lpAdapter == NULL)
				SetLastError(ERROR_BAD_UNIT); 
			return lpAdapter;
		}
	}
	if(TAdInfo->Flags != INFO_FLAG_NDIS_ADAPTER)
	{
		if(TAdInfo->Flags & INFO_FLAG_NDISWAN_ADAPTER)
		{
			lpAdapter = (LPADAPTER) GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT,
				sizeof(ADAPTER));
			if (lpAdapter == NULL)
			{
				if (AdapterNameU != NULL) GlobalFreePtr(AdapterNameU);
				else GlobalFreePtr(AdapterNameA);
				ReleaseMutex(AdaptersInfoMutex);
				SetLastError(ERROR_BAD_UNIT);
				return NULL;
			}
			lpAdapter->Flags = TAdInfo->Flags;
			lpAdapter->pWanAdapter = WanPacketOpenAdapter();
			if (lpAdapter->pWanAdapter == NULL)
			{
				if (AdapterNameU != NULL) GlobalFreePtr(AdapterNameU);
				else GlobalFreePtr(AdapterNameA);
				GlobalFreePtr(lpAdapter);
				ReleaseMutex(AdaptersInfoMutex);
				SetLastError(ERROR_BAD_UNIT);
				return NULL;
			}
			_snprintf(lpAdapter->Name, ADAPTER_NAME_LENGTH, "%s", AdapterNameA);
			lpAdapter->ReadEvent = WanPacketGetReadEvent(lpAdapter->pWanAdapter);
			if (AdapterNameU != NULL) 
				GlobalFreePtr(AdapterNameU);
			else 
				GlobalFreePtr(AdapterNameA);
			ReleaseMutex(AdaptersInfoMutex);
			return lpAdapter;
		}
		else
			if(TAdInfo->Flags & INFO_FLAG_DAG_CARD)
			{
				lpAdapter = PacketOpenAdapterDAG(AdapterNameA, FALSE);
				if (AdapterNameU != NULL) 
					GlobalFreePtr(AdapterNameU);
				else 
					GlobalFreePtr(AdapterNameA);
				ReleaseMutex(AdaptersInfoMutex);
				if (lpAdapter == NULL)
					SetLastError(ERROR_BAD_UNIT);
				return lpAdapter;
			}
		else
			if(TAdInfo->Flags == INFO_FLAG_DONT_EXPORT)
			{
				ODSEx("The user openend the adapter %s which is flagged as not exported", AdapterNameA);
				if (AdapterNameU != NULL) GlobalFreePtr(AdapterNameU);
				else GlobalFreePtr(AdapterNameA);
				ReleaseMutex(AdaptersInfoMutex);
				SetLastError(ERROR_BAD_UNIT);
				return NULL;
			}
	}
	ReleaseMutex(AdaptersInfoMutex);
#endif 
	lpAdapter = PacketOpenAdapterNPF(AdapterName);
	if (AdapterNameU != NULL) 
		GlobalFreePtr(AdapterNameU);
	else 
		GlobalFreePtr(AdapterNameA);
	return lpAdapter;
}
LPADAPTER PacketOpenAdapter ( PCHAR AdapterName ) { LPADAPTER lpAdapter ; WCHAR * AdapterNameU ; SC_HANDLE svcHandle = NULL ; PCHAR AdapterNameA = NULL ; #ifndef _WINNT4 PADAPTER_INFO TAdInfo ; #endif ODSEx ( " \n " , AdapterName ) if ( AdapterName [ 1 ] != 0 ) { AdapterNameU = SChar2WChar ( AdapterName ) ; AdapterNameA = AdapterName ; AdapterName = ( PCHAR ) AdapterNameU ; } else { AdapterNameU = NULL ; AdapterNameA = WChar2SChar ( ( PWCHAR ) AdapterName ) ; } #ifndef _WINNT4 WaitForSingleObject ( AdaptersInfoMutex , INFINITE ) ; TAdInfo = PacketFindAdInfo ( AdapterNameA ) ; if ( TAdInfo == NULL ) { PacketUpdateAdInfo ( AdapterNameA ) ; TAdInfo = PacketFindAdInfo ( AdapterNameA ) ; if ( TAdInfo == NULL ) { lpAdapter = PacketOpenAdapterDAG ( AdapterNameA , TRUE ) ; if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; ReleaseMutex ( AdaptersInfoMutex ) ; if ( lpAdapter == NULL ) SetLastError ( ERROR_BAD_UNIT ) ; return lpAdapter ; } } if ( TAdInfo -> Flags != INFO_FLAG_NDIS_ADAPTER ) { if ( TAdInfo -> Flags & INFO_FLAG_NDISWAN_ADAPTER ) { lpAdapter = ( LPADAPTER ) GlobalAllocPtr ( GMEM_MOVEABLE | GMEM_ZEROINIT , sizeof ( ADAPTER ) ) ; if ( lpAdapter == NULL ) { if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; ReleaseMutex ( AdaptersInfoMutex ) ; SetLastError ( ERROR_BAD_UNIT ) ; return NULL ; } lpAdapter -> Flags = TAdInfo -> Flags ; lpAdapter -> pWanAdapter = WanPacketOpenAdapter ( ) ; if ( lpAdapter -> pWanAdapter == NULL ) { if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; GlobalFreePtr ( lpAdapter ) ; ReleaseMutex ( AdaptersInfoMutex ) ; SetLastError ( ERROR_BAD_UNIT ) ; return NULL ; } _snprintf ( lpAdapter -> Name , ADAPTER_NAME_LENGTH , " " , AdapterNameA ) ; lpAdapter -> ReadEvent = WanPacketGetReadEvent ( lpAdapter -> pWanAdapter ) ; if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; ReleaseMutex ( AdaptersInfoMutex ) ; return lpAdapter ; } else if ( TAdInfo -> Flags & INFO_FLAG_DAG_CARD ) { lpAdapter = PacketOpenAdapterDAG ( AdapterNameA , FALSE ) ; if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; ReleaseMutex ( AdaptersInfoMutex ) ; if ( lpAdapter == NULL ) SetLastError ( ERROR_BAD_UNIT ) ; return lpAdapter ; } else if ( TAdInfo -> Flags == INFO_FLAG_DONT_EXPORT ) { ODSEx ( " " , AdapterNameA ) ; if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; ReleaseMutex ( AdaptersInfoMutex ) ; SetLastError ( ERROR_BAD_UNIT ) ; return NULL ; } } ReleaseMutex ( AdaptersInfoMutex ) ; #endif lpAdapter = PacketOpenAdapterNPF ( AdapterName ) ; if ( AdapterNameU != NULL ) GlobalFreePtr ( AdapterNameU ) ; else GlobalFreePtr ( AdapterNameA ) ; return lpAdapter ; }
\brief Opens an adapter.
\ brief Opens an adapter .
// _WINNT4
 //
 // ASCII
 //
 //
 // Unicode
 //
 // Find the PADAPTER_INFO structure associated with this adapter 
 //can be an ERF file?
 //this is the best we can do....
 //
 // Check adapter type
 //
 //
 // Not a standard NDIS adapter, we must have specific handling
 //
 //
 // This is a wan adapter. Open it using the netmon API
 //			
 // Backup flags for future usage
 // Open the adapter
 //
 // This is a Dag card. Open it using the dagc API
 //								
 //
 // The adapter is flagged as not exported, probably because it's broken 
 // or incompatible with WinPcap. We end here with an error.
 //
 // _WINNT4
