Hi Prasanna Kumar Nelam, Following links might be helpful: http://www.winpcap.org/pipermail/winpcap-users/2006-September/001464.html http://www.winpcap.org/pipermail/winpcap-users/2007-May/001858.html
Good luck Peter On Tue, Jul 14, 2009 at 8:27 PM, Prasanna Kumar Nelam<[email protected]> wrote: > Dear All, > > > > I am using pcap_next_ex() API to read the packets from Network. In my > application I implemented 2 threads one for reading the packets from > network, and other for process these packets. > > I am giving the code snippet, can u please suggest me whether it is correct > or not. > > > > while(true) > > { > > while((res=pcap_next_ex(pcap.m_padhandle,&header,&pkt_data))>0) > > { > > > /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > The lines below are used to copy the captured pkt into our local buffer > > > > packet_capture *packet=new packet_capture(); > > > packet->header=(pcap_pkthdr*)malloc(sizeof(pcap_pkthdr)+1);//header; > > > memset((void*)packet->header,0,(sizeof(pcap_pkthdr)+1)); > > memcpy(packet->header,header,sizeof(pcap_pkthdr)); > > packet->pkt_data=(unsigned > char*)malloc((int)header->caplen+1); > > > memset((void*)packet->pkt_data,0,(int)header->caplen+1); > > > memcpy((void*)packet->pkt_data,(void*)pkt_data,(int)header->caplen); > > > /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > > ************************************************************************************************************************************ > > The following lines are used to put the packet into > queue, the packets from this C++queue are read by another thread > > { > > CAutoLock lock(g_syncpkt); > > pkt_capture.push(packet); > > printf("\n the queue size > is:%d\n",pkt_capture.size()); > > } > > > *************************************************************************************************************************************** > > Sleep(1); > > } > > if(res==-1) > > { > > printf("Error reading the packets: %s\n", > pcap_geterr(pcap.m_padhandle)); > > FILE *fp; > > fp=fopen("exceptionhandler.log","a"); > > fprintf(fp,"%s-%s\n","Error reading the packets", > pcap_geterr(pcap.m_padhandle)); > > fclose(fp); > > > > } > > Sleep(1); > > > > } > > > > My doubt is it correct to write Sleep() at the > while((res=pcap_next_ex(pcap.m_padhandle,&header,&pkt_data))>0) loop, by > putting the sleep shall we loss any packet. > > > > Before intrducing the Sleep() in the code, I am getting delayed processing > thread, and I am not able to process the packets immediately after > capturing, because of that the virtual memory is increasing. > > Thanks in Advance for your advice. > > > > > > > > Thanks and Regds, > > Prasanna Kumar.N, > > Software Engineer, > > R&D Networks, > > Mob:9000086538 > > > > ============================================= > > > > This email and any files transmitted with it are confidential and intended > solely for the use of the individual or entity to whom they are addressed. > If you have received this email in error, please notify the sender > immediately by e-mail and delete this e-mail from your system. The sender > therefore does not accept liability for any errors or omissions in the > contents of this message, which arise as a result of e-mail transmission. > Please note that any views or opinions presented in this email are solely > those of the author and do not necessarily represent those of the company. > Finally, the recipient should check this email and any attachments for the > presence of viruses. The company accepts no liability for any damage caused > by any attachment with this email. > > IMImobile, Plot No:770, Road No : 44, Jubilee Hills, Hyderabad, India, > 500033. www.imimobile.com > ========================================================================================================================================================== > This e-mail message has been scanned for Viruses and Content and cleared by > Symantec Mail Security > > > > > _______________________________________________ > Winpcap-users mailing list > [email protected] > https://www.winpcap.org/mailman/listinfo/winpcap-users > > _______________________________________________ Winpcap-users mailing list [email protected] https://www.winpcap.org/mailman/listinfo/winpcap-users
