packet里有一控制台例程TESTAPP
里面有一小段:
while(!kbhit())
{
// capture the packets
if(PacketReceivePacket(lpAdapter,lpPacket,TRUE)==FALSE)
{
printf("Error: PacketReceivePacket failed");
return (-1);
} PrintPackets(lpPacket);
}
请将其修改成windows下的,即用什么代替khhit()
里面有一小段:
while(!kbhit())
{
// capture the packets
if(PacketReceivePacket(lpAdapter,lpPacket,TRUE)==FALSE)
{
printf("Error: PacketReceivePacket failed");
return (-1);
} PrintPackets(lpPacket);
}
请将其修改成windows下的,即用什么代替khhit()
{
}停止的时候将bwhile=1
{
///////////////////////////////////
//define a pointer to an ADAPTER structure
LPADAPTER lpAdapter = 0;
//define a pointer to a PACKET structure
LPPACKET lpPacket;
int i;
DWORD dwErrorCode;
int AdapterNum=0;
ULONG AdapterLength;
char buffer[8192]; // buffer to hold the data coming from the driver
// char buffer[256000]; // buffer to hold the data coming from the driver// struct bpf_stat stat;
// obtain the name of the adapters installed on this machine
AdapterLength=4096;
i=0;
// the data returned by PacketGetAdapterNames is different in Win95 and in WinNT.
// We have to check the os on which we are running
//这里对网卡进行选择
char Adapter[MAX_PATH];
memset(Adapter, 0, MAX_PATH);
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)AdapterList[g_AdapterNum], wcslen((LPWSTR)AdapterList[g_AdapterNum])+1, Adapter, MAX_PATH, NULL, NULL); lpAdapter = (LPADAPTER) PacketOpenAdapter(Adapter);
// lpAdapter = (LPADAPTER) PacketOpenAdapter((LPTSTR) AdapterList[0]);
// lpAdapter = (LPADAPTER) PacketOpenAdapter((LPTSTR) AdapterList[g_AdapterNum]);
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
{
dwErrorCode=GetLastError();
AfxMessageBox("Unable to open the adapter, Error Code : %lx\n",dwErrorCode);
return -1;
} // set the network adapter in promiscuous mode
if(PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS)==FALSE){
AfxMessageBox("Warning: unable to set promiscuous mode!\n");
} // set a 512K buffer in the driver
if(PacketSetBuff(lpAdapter,512000)==FALSE){
AfxMessageBox("Unable to set the kernel buffer!\n");
return -1;
} // set a 1 second read timeout
if(PacketSetReadTimeout(lpAdapter,1000)==FALSE){
AfxMessageBox("Warning: unable to set the read tiemout!\n");
} //allocate and initialize a packet structure that will be used to
//receive the packets.
if((lpPacket = PacketAllocatePacket())==NULL){
AfxMessageBox("\nError: failed to allocate the LPPACKET structure.");
return (-1);
}
PacketInitPacket(lpPacket,(char*)buffer,8192);
//main capture loop
while(1)//this you change it to 1
{
// capture the packets
if(PacketReceivePacket(lpAdapter,lpPacket,TRUE)==FALSE){
AfxMessageBox("Error: PacketReceivePacket failed");
return (-1);
}
AnalysePackage(lpPacket,lpAdapter);//this is your analyse packet thread
}
PacketFreePacket(lpPacket);
PacketCloseAdapter(lpAdapter);
return 0;
}
如何用消息令此线程退出
or get thread handle ,then ExitThread
thanks a lot
and if i can not debug it,I will post it to you
can i?