Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] add functions to be able to get packet's savefile offset #491

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

alexandretea
Copy link

I noticed there was no way through the API to get a packet's savefile offset, so I added those functions in order to resolve this problem :
pcap_next_with_sf_offset() and pcap_next_ex_with_sf_offset()

They work the same as pcap_next() and pcap_next_ex() but takes an additional pointer on a long, which will be set to the packet's savefile offset. If the packets are read from a live capture, then this long will be set to -1.

This feature would be useful for a project I work on, which aim is to retrieve packets from pcap[-ng] files and then process them. I need to keep their savefile offsets to be able to retrieve their raw format at any time, after the processing.
It may also be useful for others :)

pcap-int.h Outdated
@@ -200,6 +200,9 @@ struct pcap {
int activated; /* true if the capture is really started */
int oldstyle; /* if we're opening with pcap_open_live() */

long lastpkt_offset; /* last packet offset in save file */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tabs, not 4 spaces, for indentation.

@alexandretea
Copy link
Author

Sorry about the indentation, I fixed it :) I also removed pcap_next_with_sf_offset().

@mcr
Copy link
Member

mcr commented Apr 26, 2019

Please rebase.

…to API

add current_offset and lastpkt_offset attributes to struct pcap

in order to be able to get a packet's savefile offset
rename pcap_next_ex_with_file_offset to pcap_next_ex_with_sf_offset
check if read from savefile to avoid useless calculations
add some code documentation
edit pcap_next_ex man page to add the pcap_next_*with_sf_offset API functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants