Вернуться к статье

Листинг 1. Классы для загрузки NAL.

class CDllHelper 
{
public:
	HINSTANCE m_hInstance;
	BOOL DoFree( void );
	BOOL DoInitialize( LPCTSTR lpszModuleName );
	CDllHelper( LPCTSTR lpszModuleName = NULL );
	virtual ~CDllHelper();
private:
	CString csModuleName;
};
CDllHelper:: CDllHelper( LPCTSTR lpszModuleName )
{
	m_hInstance		= NULL;
	csModuleName		= «»;
	if(lpszModuleName != NULL )
		DoInitialize( lpszModuleName );
}
CDllHelper::~CDllHelper()
{
	DoFree();
}
BOOL CDllHelper::DoInitialize(LPCTSTR lpszModuleName)
{
	BOOL	bRetVal	= FALSE;
	DoFree();
	if( lpszModuleName != NULL )
	{
		m_hInstance = LoadLibrary( lpszModuleName );
		if( m_hInstance != NULL )
		{
			csModuleName = lpszModuleName;
			bRetVal = TRUE;
		}
	}
	return bRetVal;
}
BOOL CDllHelper::DoFree()
{
	BOOL	bRetVal	= FALSE;
	if( m_hInstance != NULL )
	{
		FreeLibrary( m_hInstance );
		m_hInstance		= NULL;
		csModuleName	= «»;
		bRetVal	= TRUE;
	}
	return bRetVal;
}

Листинг 2. Класс для работы с NAL.

class CNal : public CDllHelper 
{
public:
	BOOL Initialize( void );
	CNal();
	virtual ~CNal();
	DWORD EnumNetworks( void );
	LPNETWORKINFO GetNetworkInfo(DWORD NetworkID);
	HNETWORK OpenNetwork(DWORD NetworkID, HPASSWORD hPassword, NETWORKPROC lpNetworkProc,
 LPVOID lpUserContext, LPSTATISTICSPARAM lpStatisticsParam );
	DWORD CloseNetwork(HNETWORK hNetwork, DWORD CloseFlags);
	DWORD StartCapturing(HNETWORK hNetwork, HBUFFER hBuffer);
	DWORD StopCapturing(HNETWORK hNetwork);
	DWORD ContinueCapturing(HNETWORK hNetwork);
	DWORD PauseCapturing(HNETWORK hNetwork);
	DWORD SetNetworkFilter(HNETWORK hNetwork, LPCAPTUREFILTER lpCaptureFilter, HBUFFER hBuffer);
	DWORD GetBufferTotalFramesCaptured(HBUFFER hBuffer);
	LPSYSTEMTIME GetBufferTimeStamp(HBUFFER hBuffer, LPSYSTEMTIME SystemTime);
	LPFRAME GetNetworkFrame(HBUFFER hBuffer, DWORD FrameNumber);
	HBUFFER AllocNetworkBuffer(DWORD NetworkID, DWORD BufferSize);
	HBUFFER FreeNetworkBuffer(HBUFFER hBuffer);
};


Вернуться к статье

Листинг 3. Запуск трассировки.

BOOL CRTNetworkAnalizerDlg::StartTrace( void )
{
	BOOL				bRetVal = FALSE;
	HPASSWORD			hPassword = NULL;
	hPassword = m_bhsupp.CreatePassword(«»);
	m_hNetwork = m_nal.OpenNetwork( GetNetworkID(),hPassword,
&CallBackProc,(LPVOID)1,&m_StatisticsParam );
	if( m_hNetwork != NULL )
	{
		m_hBuffer = m_nal.AllocNetworkBuffer( GetNetworkID(),BUFFERSIZE
 * BUFFER_FACTOR ); 
		if( m_hBuffer != NULL )
		{
			memset( &m_filter,0,sizeof(CAPTUREFILTER) );
			m_filter.FilterFlags = CAPTUREFILTER_FLAGS_INCLUDE_ALL
_SAPS | CAPTUREFILTER_FLAGS_INCLUDE_ALL_ETYPES;
			m_nal.SetNetworkFilter( m_hNetwork,&m_filter,m_hBuffer );
			m_nal.StartCapturing( m_hNetwork,m_hBuffer );
			rt_StartTimer();
			bRetVal = TRUE;
		}
	}
	return bRetVal;
}


Вернуться к статье