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

Return errors from pcap_dump and pcap_dump_close #1048

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

Conversation

rigtorp
Copy link

@rigtorp rigtorp commented Aug 25, 2021

  • Add new functions pcap_dump1, pcap_dump_close1 that returns PCAP_ERROR on error
  • Update manpages
  • Update CMakeLists.txt to install symlinks for new manpages
  • Update Makefile.in to install symlinks for new manpages
  • Update CHANGES

Closes #1047

@rigtorp rigtorp changed the title Return errors from pcap_dump and pcap_dump_close WIP Return errors from pcap_dump and pcap_dump_close Aug 25, 2021
@rigtorp rigtorp force-pushed the add-dump-error-handling branch 3 times, most recently from 821e1c1 to b7b52e3 Compare August 25, 2021 16:09
@rigtorp rigtorp changed the title WIP Return errors from pcap_dump and pcap_dump_close Return errors from pcap_dump and pcap_dump_close Aug 25, 2021
@infrastation
Copy link
Member

Thank you for proposing these changes. Regardless of the more substantial aspects, which also need to be reviwed, it would be difficult to remember the difference between pcap_dump1() and pcap_dump() (or pcap_dump2() if there is another variation in future). It would be easier with a name like pcap_dump_reliably(), pcap_dump_or_fail() or some such.

@guyharris
Copy link
Member

Thank you for proposing these changes. Regardless of the more substantial aspects, which also need to be reviwed, it would be difficult to remember the difference between pcap_dump1() and pcap_dump() (or pcap_dump2() if there is another variation in future). It would be easier with a name like pcap_dump_reliably(), pcap_dump_or_fail() or some such.

+1

pcap_dump_check_error()/pcap_close_check_error() is another alternative for the names.

@rigtorp
Copy link
Author

rigtorp commented Aug 25, 2021 via email

@rigtorp
Copy link
Author

rigtorp commented Aug 26, 2021 via email

@rigtorp
Copy link
Author

rigtorp commented Sep 1, 2021

@guyharris @infrastation any updates regarding the naming?

@rigtorp
Copy link
Author

rigtorp commented Sep 15, 2021

@guyharris @infrastation reminding you about this again.

@infrastation
Copy link
Member

Thank you for waiting. Naming consistency within a project usually works better than naming consistency between different projects, so it seems likely that before the new function names get set in stone they should be made to make the most sense to libpcap API users.

A good usage example for the new functions would be in tcpdump source code, this would also make it easier to confirm everything fits as expected. I have made a look at tcpdump.c with this in mind.

The first instance of pcap_dump_close() closes the file before opening the next one. Assuming a single file error should not abort the sequence, the only use for checking the return value of pcap_dump_close_GHPR1048() would be to skip the file compression and to print a warning message. In which case it would be useful to explain the error condition. Which makes me think it might be useful to mention in the man pages that when a new function returns PCAP_ERROR, the calling function can use errno to work the cause out.

The second instance looks similar.

The first instance of pcap_dump() knows it is writing to a file in a sequence, but it does not know how many more packets the current file is going to have, so the above thinking likely does not stand and the only reasonable thing to do on the first failed packet would be to fail right away with an error message. Which, again, would benefit from a meaningful error cause.

The second instance of pcap_dump() knows it is writing a single file, but for consistency and simplicity it seems best to treat all errors as hard errors.

The above changes in tcpdump would need to be conditional depending on HAVE_PCAP_DUMP_CLOSE_GHPR1048 and HAVE_PCAP_DUMP_GHPR1048 or some such, so tcpdump continues to compile with older libpcap versions. Thus the complication is not only in the proposed changes itself, but also in the incurred changes. So it would be best not to rush this before verifying everything.

@rigtorp
Copy link
Author

rigtorp commented Sep 16, 2021 via email

@mcr
Copy link
Member

mcr commented Sep 18, 2021

Any name is fine with me, I only care about the functionality.

Yeah, but names accumulate, get in the way, and confuse people.
I'm trying to assemble some discussion about evolving the API.
Go ahead and work on any code you think makes sense to you, but don't get too attached to names yet.

pcap_dump.3pcap Outdated
@@ -30,6 +30,9 @@ pcap_dump \- write a packet to a capture file
void pcap_dump(u_char *user, struct pcap_pkthdr *h,
.ti +8
u_char *sp);
int pcap_dump(u_char *user, struct pcap_pkthdr *h,
Copy link
Member

Choose a reason for hiding this comment

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

pcap_dump1

@infrastation
Copy link
Member

Now that pull request #494 has been merged, this change needs to be rebased.

@rigtorp
Copy link
Author

rigtorp commented Sep 25, 2023

@infrastation I fixed the manpage and rebased!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

pcap_dump should return -1 on fwrite error
4 participants