Recognise more iputils ping error strings#23
Merged
Conversation
- "no answer yet for icmp_seq=N" (emitted under -O / showLostPackets) now maps to Timeout instead of UnknownError. - "Destination Net/Port/Host Unreachable" ICMP replies all map to HostUnreachable via a single regex.
Every other regex in PingResult.php uses single-backslash \s in single-quoted strings; the new pattern used \\s. Both are functionally identical, this just aligns the style. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
Thanks! |
Replace the per-error if/str_contains chain and the lone unreachable regex with a declarative [error, needles] table matched via array_any. The regex's optional 'destination ' prefix made it equivalent to plain net/port/host unreachable substring checks, so it is no longer needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small additions to
PingResult::determineErrorFromOutput()so that real-world iputils output stops falling through toUnknownError:no answer yet for icmp_seq=N->Timeout. This line is emitted by iputils when the-Oflag is set, which this package enables by default viashowLostPackets. It indicates a sequence number that hasn't been answered by the next interval tick, semantically a timeout. Today an all-lost ping with-Oexits non-zero with only "no answer yet" + "100% packet loss" in the output and gets classified asUnknownError.Destination Net/Port/Host Unreachable->HostUnreachable. iputils prints these when an intermediate router replies with an ICMP unreachable. The existinghost unreachablesubstring check catches the "Destination Host" variant by accident, but misses "Destination Net" and "Destination Port". Folded the three into one regex so all variants are matched in a single pass.Sources in iputils:
ping/ping_common.cfor theno answer yet for icmp_seq=print (gated onopt_outstanding, i.e.-O),ping/ping.cfor the ICMP unreachable strings.Tests added covering all three "Destination ... Unreachable" variants and a full "no answer yet" output block.