-
Notifications
You must be signed in to change notification settings - Fork 637
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
Improve nanosecond precision support for pcap #1368
Conversation
@@ -61,6 +61,7 @@ Tests/Pcap++Test/cUrl/curl_output.txt | |||
*.VC.db | |||
*.vcxproj.user | |||
**/.vs | |||
CMakeSettings.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Visual Studio generated file to hold configuration when remote compilation (ssh/wsl etc) requested or modify build mode from UI
Manually tested, it looks like it works for |
@egecetin why can't we write tests for it? 🤔 |
@seladb If i can figure out a test flow yes, it is possible 😀. One way I'm thinking.
If I'm right only missed part with this flow, if somehow, I write mathematically inverse operations in write and read only the pcap file itself will be wrong but all other cases should be covered right? 🤔 |
Yes, I think it's a valid test that mostly covers what is mentioned in the ticket: #906 (comment)
|
Actually, for the reading side there is no option implemented. It always uses as much high as precision always. So only WinPcap will use microsecond, and all other systems/tests will use nanosecond for reading mode. So, I added a function |
@seladb It is ready to review again |
@seladb Probably I addressed all your comments. Can you review it again when you have time? |
/** | ||
* @return The precision of the timestamps in the file. | ||
*/ | ||
FileTimestampPrecision getTimestampPrecision() const { return m_Precision; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better test coverage, maybe we can add tests for this method?
It'll actually be interesting to test it before opening the file and after opening it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only added tests for PcapFileWriterDevice::getTimestampPrecision()
but not for PcapFileReaderDevice::getTimestampPrecision()
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seladb libpcap
scales precision because of pcap_open_offline_with_tstamp_precision
behaviour. So, I added a test and updated comments of reader function. Can you take a look again before merging for anything i missed?
https://www.tcpdump.org/manpages/pcap_open_offline.3pcap.html
pcap_open_offline_with_tstamp_precision() takes an additional precision argument specifying the time stamp precision desired; if PCAP_TSTAMP_PRECISION_MICRO is specified, packet time stamps will be supplied in seconds and microseconds, and if PCAP_TSTAMP_PRECISION_NANO is specified, packet time stamps will be supplied in seconds and nanoseconds. If the time stamps in the file do not have the same precision as the requested precision, they will be scaled up or down as necessary before being supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see this last comment: #1368 (comment)
Can you fix it before merging?
Instead of compile time constant definitionsusepcap_get_tstamp_precision()
to detect timestamp precision which introduced with libpcap 1.5.1This should also fix #906