tcpdump mailing list archives
Re: Buffer overwrites with pcap_next_ex
From: Guy Harris <guy () alum mit edu>
Date: Sat, 24 Jan 2009 11:01:10 -0800
On Jan 24, 2009, at 6:36 AM, Andreas Rieke wrote:
I have seen a strange behavior of pcap_next_ex where a buffer isoverwritten. When pcap_next_ex has finished, it returns a buffer for thepacket header and one for the packet data.
No. pcap_next_ex() returns a pointer to a packet header and a pointer to packet data.
These are, in fact, pointers to a structure internal to libpcap and a buffer internal to libpcap, respectively - and those buffers can be reused, and hence overwritten, by subsequent calls to pcap_next_ex() (or pcap_next() or pcap_dispatch() or pcap_loop()).
When processing the packetdata, I have often seen strange data. For that reason, I have changed my code to copy – for debug purposes - the packet data into a buffer, after that process them and in the last step compare to the original data: Ithas changed, although I am sure that my code does not write into that buffer!
Do you make any pcap_next_ex() calls (or pcap_next() or pcap_dispatch() or pcap_loop() calls) in between copying the data and comparing it? If so, that could cause the symptoms you're seeing, for the reason described above.
Is it recommended to copy the data (which takes additional time) before processing them?
Only if you want to continue use the data from one pcap_next_ex() call after you make subsequent pcap_next_ex() calls.
In future, I would like toprocess multiple interfaces using select/pcap_dispatch. Will I have thesame problems there?
You won't have that problem *between* interfaces, because each pcap_t has its own buffer.-
This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- Buffer overwrites with pcap_next_ex Andreas Rieke (Jan 24)
- Re: Buffer overwrites with pcap_next_ex Guy Harris (Jan 24)
- Re: Buffer overwrites with pcap_next_ex Guy Harris (Jan 24)
- Re: Buffer overwrites with pcap_next_ex Andreas Rieke (Jan 26)
- Re: Buffer overwrites with pcap_next_ex Guy Harris (Feb 14)
- Re: Buffer overwrites with pcap_next_ex Michael Bernstein (Feb 15)
- Re: Buffer overwrites with pcap_next_ex Andreas Rieke (Feb 15)
- Re: Buffer overwrites with pcap_next_ex Guy Harris (Jan 24)