Skip to content

Recognise more iputils ping error strings#23

Merged
freekmurze merged 3 commits into
spatie:mainfrom
mattiasgeniar:improve-error-detection
May 22, 2026
Merged

Recognise more iputils ping error strings#23
freekmurze merged 3 commits into
spatie:mainfrom
mattiasgeniar:improve-error-detection

Conversation

@mattiasgeniar
Copy link
Copy Markdown
Contributor

Two small additions to PingResult::determineErrorFromOutput() so that real-world iputils output stops falling through to UnknownError:

  1. no answer yet for icmp_seq=N -> Timeout. This line is emitted by iputils when the -O flag is set, which this package enables by default via showLostPackets. It indicates a sequence number that hasn't been answered by the next interval tick, semantically a timeout. Today an all-lost ping with -O exits non-zero with only "no answer yet" + "100% packet loss" in the output and gets classified as UnknownError.

  2. Destination Net/Port/Host Unreachable -> HostUnreachable. iputils prints these when an intermediate router replies with an ICMP unreachable. The existing host unreachable substring 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.c for the no answer yet for icmp_seq= print (gated on opt_outstanding, i.e. -O), ping/ping.c for the ICMP unreachable strings.

Tests added covering all three "Destination ... Unreachable" variants and a full "no answer yet" output block.

mattiasgeniar and others added 2 commits May 21, 2026 13:38
- "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>
@freekmurze
Copy link
Copy Markdown
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>
@freekmurze freekmurze merged commit 5d02378 into spatie:main May 22, 2026
1 check passed
@mattiasgeniar mattiasgeniar deleted the improve-error-detection branch May 23, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants