I have a problem receiving packets in my main capture loop. I call the ListenThread function from my program and start a new thread (it's not the thread that causes the problem, I still have the problem without it). The function packetReceivePacket(m_lpAdapter,lpPacket,TRUE) gives signals that I receive packets even when there aren't any packets send (I'm sure no packets are send, I watch the traffic with Ethereal), even when my computer is disconnected from any network, it still gives signals! The code is written under Visual C++ maybe that's a problem??? My adapter is good initialated, I can send packets (Ethereal shows them). So my question is: what's going wrong??? and of course, how do I solve this! Thank U.
 
AfxBeginThread(ListenThread,this);
 
UINT CPIGDlg::ListenThread(LPVOID pParam)
{
 CPIGDlg * dlg = (CPIGDlg *) pParam;
 dlg->ListenThread();
 return 0;
}
 
void CPIGDlg::ListenThread()
{
 LPPACKET   lpPacket;
 char buffer[256000];
 
 if (!m_lpAdapter || (m_lpAdapter->hFile == INVALID_HANDLE_VALUE))
 {
  AfxMessageBox("Unable to open the adapter");
 } 
 
 // set the network adapter in promiscuous mode
 if(PacketSetHwFilter(m_lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS)==FALSE){
   AfxMessageBox("Warning: unable to set promiscuous mode!\n");
 }
 
 // set a 512K buffer in the driver
 if(PacketSetBuff(m_lpAdapter,512000)==FALSE){
   AfxMessageBox("Unable to set the kernel buffer!\n");
 }
 
 // set a 1 second read timeout
 if(PacketSetReadTimeout(m_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.");
 }
 PacketInitPacket(lpPacket,(char*)buffer,256000);
 
 //main capture loop
 while(true)
 {
     // capture the packets
  if(PacketReceivePacket(m_lpAdapter,lpPacket,TRUE)==FALSE){
   MessageBox("Error: PacketReceivePacket failed");
  }
  else{
   AfxMessageBox("packet captured");
  }
 }
 
 PacketFreePacket(lpPacket);
 // close the adapter and exit
 PacketCloseAdapter(m_lpAdapter);
}

Reply via email to