亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? wanpacket.cpp

?? Windows XP下的抓包程序實現
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
	HRESULT hResult;
	DWORD i;

	if ( g_hModule == NULL)
	{
		g_hModule = LoadLibrary("npp\\ndisnpp.dll");
	}

	if ( g_hModule == NULL)
	{
		return NULL;
	}

	hResult = CoInitialize(NULL);

	//
 	// if  the calling thread has already initialized COM with a 
 	// different threading model, we have this error
 	// however, we are able to support another threading model,
 	// so we try to initialize COM with another threading model.
 	// This new call should succeed with S_FALSE.
 	//
 	if (hResult == RPC_E_CHANGED_MODE)
	{
		hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	
		//MULTITHREADED threading is only supported on Windows 2000
		if (hResult == RPC_E_CHANGED_MODE && IsWindows2000())
		{
			hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
		}
	}

	if (hResult != S_OK && hResult != S_FALSE)
		return NULL;

	pWanAdapter = (PWAN_ADAPTER)GlobalAlloc(GPTR, sizeof (WAN_ADAPTER));

	if ( pWanAdapter == NULL )
		goto error;
	
	memset(pWanAdapter, 0, sizeof(WAN_ADAPTER));
	
	if ( CreateBlob(&hFilterBlob) != NMERR_SUCCESS )
	{
		goto error;
	}
	
	if ( SetBoolInBlob(hFilterBlob, OWNER_NPP, CATEGORY_CONFIG, TAG_INTERFACE_REALTIME_CAPTURE, TRUE) != NMERR_SUCCESS )
	{
		DestroyBlob( hFilterBlob);
		goto error;
	}

	if ( SetBoolInBlob(hFilterBlob, OWNER_NPP, CATEGORY_LOCATION, TAG_RAS, TRUE) != NMERR_SUCCESS )
	{
		DestroyBlob( hFilterBlob);
		goto error;
	}

	if ( GetNPPBlobTable(hFilterBlob, &pBlobTable) != NMERR_SUCCESS )
	{
		DestroyBlob( hFilterBlob);
		goto error;
	}

	DestroyBlob (hFilterBlob);

	if ( pBlobTable->dwNumBlobs == 0 || pBlobTable->dwNumBlobs > 1)
	{
		///fixme.....
		for ( i = 0 ; i < pBlobTable->dwNumBlobs ; i++ )
			DestroyBlob(pBlobTable->hBlobs[i]);
		
		GlobalFree(pBlobTable);
		goto error;
	}

	pWanAdapter->hCaptureBlob = pBlobTable->hBlobs[0];

	GlobalFree(pBlobTable);

	InitializeCriticalSection(&pWanAdapter->CriticalSection);

	pWanAdapter->hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	if ( pWanAdapter->hReadEvent == NULL )
		goto error;

	pWanAdapter->MemEx.buffer = (PUCHAR)GlobalAlloc(GPTR, DEFAULT_MEM_EX_SIZE);
	if (pWanAdapter->MemEx.buffer == NULL)
		goto error;
	
	pWanAdapter->MemEx.size = DEFAULT_MEM_EX_SIZE;
	pWanAdapter->Tme.active = TME_NONE_ACTIVE;

	if (CreateNPPInterface(pWanAdapter->hCaptureBlob, IID_IRTC, (void**) &pWanAdapter->pIRTC) == NMERR_SUCCESS && pWanAdapter->pIRTC != NULL) 
	{
		//create OK
		if (pWanAdapter->pIRTC->Connect(pWanAdapter->hCaptureBlob, NULL, WanPacketReceiverCallback, (LPVOID)pWanAdapter , NULL) == NMERR_SUCCESS)
		{
			//connect OK
			if (pWanAdapter->pIRTC->Start() == NMERR_SUCCESS)
			{
				return pWanAdapter;
			}
			else
			{
				pWanAdapter->pIRTC->Disconnect();
				pWanAdapter->pIRTC->Release();
				goto error;
			}
		}
		else
		{
			pWanAdapter->pIRTC->Release();
			goto error;
		}
	}
	else
	{
		goto error;
	}

	//awfully never reached
//	return NULL;

error:

	if (pWanAdapter != NULL)
	{
		if (pWanAdapter->hReadEvent != NULL)
			CloseHandle(pWanAdapter->hReadEvent);

		DeleteCriticalSection(&pWanAdapter->CriticalSection);
		if (pWanAdapter->hCaptureBlob)
			DestroyBlob(pWanAdapter->hCaptureBlob);

		GlobalFree(pWanAdapter);
	}

	CoUninitialize();
	
	return NULL;
}

/*! 
  \brief Closes a wan (dialup, vpn...) adapter.
  \param lpWanAdapter the pointer to the wan adapter to close. 

  WanPacketCloseAdapter closes the given adapter and frees the associated WAN_ADAPTER structure
*/
BOOLEAN WanPacketCloseAdapter(PWAN_ADAPTER pWanAdapter)
{
	if (pWanAdapter->pIRTC->Stop() != NMERR_SUCCESS)
		OutputDebugString("WanPacketCloseAdapter: Severe error, IRTC::Stop failed\n");
	if (pWanAdapter->pIRTC->Disconnect() != NMERR_SUCCESS)
		OutputDebugString("WanPacketCloseAdapter: Severe error, IRTC::Disconnect failed\n");
	if (pWanAdapter->pIRTC->Release() != NMERR_SUCCESS)
		OutputDebugString("WanPacketCloseAdapter: Severe error, IRTC::Release failed\n");
	Sleep(0); //Just a stupid hack to make all the stuff work. I don't why it's necessary.


	//setting a NULL filter will actually deallocate the in-use filter
	WanPacketSetBpfFilter(pWanAdapter, NULL, 0);
	//setting a zero-sized buffer will deallocate any in-use ring buffer
	WanPacketSetBufferSize(pWanAdapter, 0);

	CloseHandle(pWanAdapter->hReadEvent);

	//destroy the BLOB used to capture
	DestroyBlob(pWanAdapter->hCaptureBlob);

	DeleteCriticalSection(&pWanAdapter->CriticalSection);

	//deallocate the extended memory, if any.
	if (pWanAdapter->MemEx.size > 0)
		GlobalFree(pWanAdapter->MemEx.buffer);

	GlobalFree(pWanAdapter);
	//uninitialize COM
	CoUninitialize();

	return TRUE;
}

/*!
  \brief Sets the working mode of a wan (dialup, vpn...) adapter.
  \param pWanAdapter Pointer to a WAN_ADAPTER structure.
  \param mode The new working mode of the adapter.
  \return If the function succeeds, the return value is true.

  For more information, see the documentation of PacketSetMode
*/


BOOLEAN WanPacketSetMode(PWAN_ADAPTER pWanAdapter, DWORD Mode)
{
	if (Mode != PACKET_MODE_CAPT && Mode != PACKET_MODE_STAT && Mode != PACKET_MODE_MON)
		return FALSE;
	pWanAdapter->Mode = Mode;
	return TRUE;
}

/*!
  \brief Sets the bpf packet filter.
  \param pWanAdapter Pointer to a WAN_ADAPTER structure.
  \param FilterCode Pointer to the BPF filtering code that will be associated with this capture or monitoring 
  instance and that will be executed on every incoming packet.
  \param Length Length, in bytes, of the BPF filter code.
  \return This function returns TRUE if the filter is set successfully, FALSE if an error occurs 
   or if the filter program is not accepted after a safeness check.  This API
   performs the check in order to avoid unexpected behavior due to buggy or malicious filters, and it rejects non
   conformant filters.

  For more information, see the documentation of PacketSetBpf
*/
BOOLEAN WanPacketSetBpfFilter(PWAN_ADAPTER pWanAdapter, PUCHAR FilterCode, DWORD Length)
{
	PUCHAR	NewFilterCode = NULL;
	DWORD NumberOfInstructions;	
	DWORD Counter;
	struct bpf_insn *InitializationCode;
	struct time_conv TimeConv;
	if ( Length < 0)
		return FALSE;

	EnterCriticalSection(&pWanAdapter->CriticalSection);
	if (Length > 0)
	{
		NumberOfInstructions = Length/sizeof(struct bpf_insn);
		for(Counter = 0; 
			Counter < NumberOfInstructions && ((struct bpf_insn*)FilterCode)[Counter].code != BPF_SEPARATION ;
			Counter++);

		if ( Counter != NumberOfInstructions &&
			NumberOfInstructions != Counter + 1 &&
			((struct bpf_insn*)FilterCode)[Counter].code == BPF_SEPARATION )
		{
			//we need to initialize the TME
			InitializationCode = &((struct bpf_insn*)FilterCode)[Counter+1];
			
			//FIXME, just an hack, this structure is never used here.		
			TimeConv.start[0].tv_sec = 0;
			TimeConv.start[0].tv_usec = 0;
			
			if ( bpf_filter_init(InitializationCode,
				&pWanAdapter->MemEx,
				&pWanAdapter->Tme,
				&TimeConv) != INIT_OK )
			{
				LeaveCriticalSection(&pWanAdapter->CriticalSection);
				return FALSE;
			}
		}

		NumberOfInstructions = Counter;

		if ( bpf_validate((struct bpf_insn*)FilterCode, Counter, pWanAdapter->MemEx.size) == 0)
		{
			//filter not validated
			//FIXME: the machine has been initialized(?), but the operative code is wrong. 
			//we have to reset the machine!
			//something like: reallocate the mem_ex, and reset the tme_core
			LeaveCriticalSection(&pWanAdapter->CriticalSection);
			return FALSE;
		}


		NewFilterCode = (PUCHAR)GlobalAlloc( GMEM_FIXED, Counter * sizeof(struct bpf_insn) );
		if (NewFilterCode == NULL)
		{
			LeaveCriticalSection(&pWanAdapter->CriticalSection);
			return FALSE;
		}
	
		RtlCopyMemory(NewFilterCode, FilterCode, Counter * sizeof(struct bpf_insn));
	}

	if ( pWanAdapter->FilterCode != NULL )
		GlobalFree(pWanAdapter->FilterCode);

	pWanAdapter->FilterCode = (struct bpf_insn*)NewFilterCode;
	//we reset all the ring buffer related counters.
	pWanAdapter->C = 0;
	pWanAdapter->P = 0;
	pWanAdapter->Free = pWanAdapter->Size;
	pWanAdapter->Accepted = 0;
	pWanAdapter->Dropped = 0;
	pWanAdapter->Received = 0;
	pWanAdapter->Nbytes.QuadPart = 0;
	pWanAdapter->Npackets.QuadPart = 0;

	LeaveCriticalSection(&pWanAdapter->CriticalSection);

	return TRUE;
}

/*!
  \brief Sets the size of the ring buffer associated with this instance.
  \param pWanAdapter Pointer to a WAN_ADAPTER structure.
  \param BufferSize New size of the buffer, in \b kilobytes.
  \return The function returns TRUE if successfully completed, FALSE if there is not enough memory to 
   allocate the new buffer.

  For more information, see the documentation of PacketSetBuff

*/
BOOLEAN WanPacketSetBufferSize(PWAN_ADAPTER pWanAdapter, DWORD BufferSize)
{
	PUCHAR	NewBuffer = NULL;
	
	if ( BufferSize < 0 || ( BufferSize > 0 && BufferSize < sizeof (struct bpf_hdr) ) )
		return FALSE;

	if ( BufferSize > 0 )
	{
		NewBuffer = (PUCHAR)GlobalAlloc( GMEM_FIXED, BufferSize );
		if (NewBuffer == NULL)
			return FALSE;
	}

	EnterCriticalSection(&pWanAdapter->CriticalSection);

	if ( pWanAdapter->Buffer != NULL )
		GlobalFree(pWanAdapter->Buffer);
    

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩电影免费在线| 欧美视频在线一区| 成人免费毛片aaaaa**| 国产精品一区二区在线观看网站 | 日韩一区二区三区免费看 | 久久综合色鬼综合色| 日韩一级欧美一级| 日韩精品中午字幕| 欧美va在线播放| 26uuu亚洲综合色| 久久久亚洲欧洲日产国码αv| 亚洲精品在线电影| 久久久久久久久久久久电影| 国产蜜臀av在线一区二区三区| 国产欧美视频在线观看| 亚洲天堂成人网| 一区二区三区高清不卡| 日韩电影在线观看网站| 久久99热国产| 成人va在线观看| 色狠狠一区二区| 欧美精品 日韩| 久久久不卡网国产精品一区| 国产农村妇女毛片精品久久麻豆| 最近日韩中文字幕| 天堂影院一区二区| 国产综合色在线视频区| 成人精品亚洲人成在线| 色狠狠色噜噜噜综合网| 777欧美精品| 久久精品日产第一区二区三区高清版 | 99久久综合狠狠综合久久| 日本道色综合久久| 欧美一级在线视频| 国产精品污污网站在线观看 | 91免费视频大全| 国产丝袜在线精品| 亚洲天堂精品在线观看| 天天色天天操综合| 国产精品一色哟哟哟| 一本高清dvd不卡在线观看| 在线播放中文一区| 国产亚洲精久久久久久| 亚洲一区二区三区四区五区黄 | 日韩一区二区三区四区| 国产欧美综合色| 亚洲成av人综合在线观看| 麻豆精品视频在线观看免费| 成人免费毛片片v| 欧美美女直播网站| 国产精品免费视频一区| 日韩av中文字幕一区二区 | 国产亚洲欧美激情| 亚洲bdsm女犯bdsm网站| 风间由美性色一区二区三区| 欧美在线看片a免费观看| 久久久久综合网| 午夜欧美一区二区三区在线播放| 国产在线一区二区综合免费视频| 色呦呦一区二区三区| 日韩免费观看高清完整版| 日韩美女啊v在线免费观看| 美女视频一区二区| 91国偷自产一区二区三区观看 | 一区二区高清免费观看影视大全| 看片的网站亚洲| 在线看国产一区| 国产日韩在线不卡| 免费在线观看不卡| 日本道精品一区二区三区| 欧美激情综合在线| 久久精品国产免费| 欧美专区亚洲专区| 国产精品国产三级国产三级人妇| 麻豆精品在线播放| 欧美日韩国产首页| 亚洲影院在线观看| zzijzzij亚洲日本少妇熟睡| 精品av久久707| 奇米一区二区三区| 欧美精品视频www在线观看 | 不卡的av网站| 欧美激情综合在线| 国内精品视频666| 欧美第一区第二区| 日本成人在线视频网站| 欧美亚洲图片小说| 亚洲乱码国产乱码精品精可以看| 成人午夜看片网址| 久久久国际精品| 国产一区二区三区久久久| 欧美电影免费观看完整版| 日韩avvvv在线播放| 欧美老女人在线| 亚洲成人免费看| 欧美性生活一区| 亚洲韩国一区二区三区| 色婷婷综合久久久中文一区二区| 《视频一区视频二区| 99精品黄色片免费大全| 国产精品久久久久久久久久久免费看| 国产乱码精品一区二区三| 精品国产一区久久| 激情深爱一区二区| 久久嫩草精品久久久久| 国产福利一区二区| 国产精品麻豆视频| 99re热视频这里只精品| 中文字幕一区二区三区在线播放| 成人福利视频在线看| 中文字幕在线免费不卡| 91亚洲精华国产精华精华液| 亚洲欧美日韩综合aⅴ视频| 91福利国产成人精品照片| 午夜影院久久久| 欧美一区二区三区免费在线看| 日韩电影免费在线看| 26uuu亚洲综合色欧美 | 精品久久久久久久久久久久久久久| 久久精品噜噜噜成人88aⅴ| www一区二区| jlzzjlzz欧美大全| 伊人婷婷欧美激情| 欧美乱熟臀69xxxxxx| 久久精品国产精品亚洲综合| 91精品国产日韩91久久久久久| 欧美日韩国产精品自在自线| 成人精品高清在线| 麻豆91在线播放| 午夜精品福利一区二区三区蜜桃| 精品国产凹凸成av人网站| 精品国产一区二区国模嫣然| 在线观看不卡一区| 不卡一区二区在线| 国产精品自拍网站| 国产一区在线精品| 日本午夜一本久久久综合| 日韩高清在线不卡| 波多野洁衣一区| 亚洲一区免费观看| 日韩欧美综合一区| 国产 日韩 欧美大片| 一区二区成人在线观看| 欧美一区二区精品| 成人a区在线观看| 亚洲国产综合在线| 精品精品欲导航| 99久久99久久精品免费看蜜桃| 视频一区二区中文字幕| 久久精品人人做| 欧美日韩在线观看一区二区| 国内成人精品2018免费看| 国产精品乱码久久久久久| 欧美日韩高清影院| 国产高清视频一区| 亚洲午夜久久久久久久久电影网 | 日本电影亚洲天堂一区| 久久草av在线| 亚洲精品免费在线观看| 精品国产91久久久久久久妲己| 色婷婷综合在线| 国产一区二区三区观看| 亚洲成a人片在线不卡一二三区| 久久久亚洲午夜电影| 欧美日韩精品一区二区在线播放| 国产91在线看| 六月丁香婷婷久久| 亚洲愉拍自拍另类高清精品| 久久久久9999亚洲精品| 欧美肥妇free| 色欧美片视频在线观看| 国产精品一区一区| 七七婷婷婷婷精品国产| 亚洲国产另类精品专区| 国产精品免费视频一区| 久久亚洲精精品中文字幕早川悠里 | 欧美久久久久久久久久| 91在线国产福利| 国产成人综合亚洲网站| 久久精品av麻豆的观看方式| 亚洲一线二线三线视频| 在线看一区二区| 国产精品免费视频观看| 成人精品视频一区二区三区| 日韩免费视频一区| 亚洲成av人片观看| 色噜噜狠狠色综合欧洲selulu| 久久久蜜桃精品| 免费高清在线视频一区·| 91在线云播放| 国产精品视频免费| 成人免费看黄yyy456| 国产亚洲精品福利| 国产成人在线视频播放| 精品av久久707| 2023国产一二三区日本精品2022| 在线观看免费亚洲| 欧美高清激情brazzers| 欧美三级视频在线| 在线精品视频免费播放|