Thank you! Now it works. But I used ulBytesReceived, because Length was different from 0 even when it was a timeout, ulBytesReceived is only different when a real packet is captured.
----- Original Message -----
Sent: Monday, June 30, 2003 7:42 PM
Subject: RE: [WinPcap-users] problem receiving packets, packetReceivePacket problem

My guess from looking at the code is that what you are seeing is a return due to timeout.  You set the read timeout to 1 second, and this should cause PacketReceivePacket to return after 1 second, even if there is no data available.
 
My suggestion to you would be, 1 if you want the receive to block, don't seet the read timeout.  Or 2, use the lPacket->length to determine how to handle the packet.
 
SLH.
 

---
Steighton Haley                          [EMAIL PROTECTED]

"There are 10 types of people in this world,
those who understand binary, and those who don't."

-----Original Message-----
From: Annie Deroo [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 29, 2003 6:19 AM
To: [EMAIL PROTECTED]
Subject: [WinPcap-users] problem receiving packets, packetReceivePacket problem

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