-
Notifications
You must be signed in to change notification settings - Fork 251
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
No error message when getprotobyname()
fails
#300
Comments
auerswal
added a commit
to auerswal/fping
that referenced
this issue
Feb 17, 2024
As mentioned in issue schweikert#300, error messages pertaining to socket creation may not be printed. But they should be corrected anyway, just as the comments. Having correct error messages also makes a fix for issue schweikert#300 more obvious, because the messages itself would not change.
We could consider changing crash_and_burn() to always output the error, independently of the verbose setting. If the program crashes, then it also should say why, even in quiet mode. |
auerswal
added a commit
to auerswal/fping
that referenced
this issue
Feb 21, 2024
This aligns crash_and_burn() with errno_crash_and_burn() and addresses issue schweikert#300.
schweikert
pushed a commit
that referenced
this issue
Feb 24, 2024
This aligns crash_and_burn() with errno_crash_and_burn() and addresses issue #300.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As mentioned in issue #201,
fping
does not print an error message whengetprotobyname()
foricmp
oripv6-icmp
fails andfping
cannot create a socket. It also directly fails, because it calls thecrash_and_burn()
function:While
crash_and_burn()
can output an error message, it does so only when theverbose_flag
is non-zero. This variable is implicitly initialized to0
at program start, then set to1
after successful socket creation and before option parsing. Thus it is always0
if socket creation fails, resulting in no error message.A quick and dirty "fix" would be to set
verbose_flag
to1
before socket creation.A probably better fix could be to use
fputs()
orfprintf()
to generate an error message, before callingexit(4)
, i.e., open coding a variant of thecrash_and_burn()
function that does not look atverbose_flag
. Instead of an open codedcrash_and_burn()
, thecrash_and_burn()
function could be changed to take theverbose_flag
as an additional argument (this would require adjusting all call sites, of course).A more comprehensive approach could be to return a negative value, e.g.
-1
, from the socket creation function, whengetprotobyname()
fails. After option parsing,fping
already checks if it could open at least one socket, and fails (in general with an error message) if it could not do so. But, this would require extensive testing, since it would introduce the possibility that IPv6-enabledfping
would continue running with only one socket, either IPv4 or IPv6, when it currently requires both sockets to be available. Testing this is not trivial, because it would need an appropriately prepared test environment wheregetprotobyname("icmp")
and/orgetprotobyname("ipv6-icmp")
fail in every possible combination.The text was updated successfully, but these errors were encountered: