tags:

views:

32

answers:

1

I saw this kind of code used in a project:

while (1) { l_numPkts = pcap_next_ex( m_pcapHandle, &header, &pkt_data); //do something memcpy(dst,pkt_data,size);
}

after the pcap_next_ex return,the packet status will be set TP_STATUS_KERNEL,which means the buf was return to kernel. code:

/* next packet */ switch (handle->md.tp_version) { case TPACKET_V1: h.h1->tp_status = TP_STATUS_KERNEL; ..

in some high speed environment,will it get a memory problem?

and what is the correct way to use pcap_next / pcap_next_ex?

A: 

There are lots of examples of working pcap examples online and helpful man pages. Try here: TCPDUMP.org We would need more of your code to answer your questions.

Shawn
well, I did found there is a bug in 0.98 (but looks it is not a formal release? download form http://public.lanl.gov/cpw/) the func 'pcap_next' or 'pcap_next_ex' are incorrect, it didn't copy the packet to a safe memory place before return to user application.
jon
Interesting. In my own testing with pcap_next I have noticed the same result as my TCP window size shrinks smaller and smaller until it reaches zero. The function wasn't emptying the receive buffer correctly and I had to rewrite to use recv() instead of the nice pcap utilities. I cant comment on that specific patch but switching to select()/recv() worked for my problem.
Shawn