Skip to content

Fix Ping RoundtripTime returning 0 for TtlExpired replies#124424

Open
lufen wants to merge 2 commits intodotnet:mainfrom
lufen:fix/ping-rtt-ttlexpired
Open

Fix Ping RoundtripTime returning 0 for TtlExpired replies#124424
lufen wants to merge 2 commits intodotnet:mainfrom
lufen:fix/ping-rtt-ttlexpired

Conversation

@lufen
Copy link
Contributor

@lufen lufen commented Feb 14, 2026

When a Ping results in TtlExpired or TimeExceeded, the underlying ICMP_ECHO_REPLY struct contains a valid round-trip time from the intermediate router. Previously this was discarded and hardcoded to 0 for all non-Success statuses.

This change reads the RTT from the reply for TtlExpired and TimeExceeded statuses in both IPv4 and IPv6 Windows code paths, matching the behavior of the raw socket implementation on Unix.

Fixes #118150

Copilot AI review requested due to automatic review settings February 14, 2026 18:26
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 14, 2026
@lufen
Copy link
Contributor Author

lufen commented Feb 14, 2026

@dotnet-policy-service agree

@dotnet-policy-service agree

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the Windows Ping implementation so PingReply.RoundtripTime is preserved for TTL-expired / time-exceeded ICMP replies (matching the behavior of underlying Windows ICMP APIs and Unix raw-socket behavior), and adds a regression test for it.

Changes:

  • Windows: populate RTT from ICMP_ECHO_REPLY / ICMPV6_ECHO_REPLY for IPStatus.TtlExpired and IPStatus.TimeExceeded (instead of hard-coding 0).
  • Tests: add an outer-loop functional test that exercises low-TTL ping behavior and asserts RTT is non-zero on supported code paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Windows.cs Preserve RTT for TTL-expired / time-exceeded replies in IPv4 and IPv6 Windows reply creation.
src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs Adds an outer-loop regression test validating RTT behavior for TTL-expired / time-exceeded replies.

Copilot AI review requested due to automatic review settings February 14, 2026 18:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copy link
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@rzikm
Copy link
Member

rzikm commented Mar 10, 2026

@lufen there are build errors after the last commit, can you please take a look?

@lufen lufen force-pushed the fix/ping-rtt-ttlexpired branch from ef52814 to 47edb25 Compare March 10, 2026 15:43
Copilot AI review requested due to automatic review settings March 10, 2026 15:43
The ICMP_ECHO_REPLY.RoundTripTime field is always populated by the
Windows ICMP API for any received reply, regardless of IP status.
Previously this was discarded and hardcoded to 0 for all non-Success
statuses. Now we always read the RTT from the reply struct, which
matches the behavior of the raw socket implementation on Unix.

This simplification is supported by Wine's open-source IcmpSendEcho
implementation which unconditionally sets RoundTripTime = recv_time -
send_time for every valid reply, and by empirical evidence from the
underlying Windows API (see issue discussion).

Fixes dotnet#118150

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lufen lufen force-pushed the fix/ping-rtt-ttlexpired branch from 47edb25 to 82aa081 Compare March 10, 2026 15:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


You can also share your feedback on Copilot code review. Take the survey.

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

Labels

area-System.Net community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ping RoundtripTime is Wrong

4 participants