Skip to content

Commit cb2d02e

Browse files
[release/7.0] Fix parsing the output of ping on Samsung phones (#80502)
* Account for different formats of ping output * Avoid allocation Co-authored-by: Simon Rozsival <[email protected]>
1 parent 0d7bb6d commit cb2d02e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.PingUtility.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ private static bool TryParseTtlExceeded(string stdout, out PingReply? reply)
131131
return false;
132132
}
133133

134-
// look for address in "From 172.21.64.1 icmp_seq=1 Time to live exceeded"
134+
// look for address in:
135+
// - "From 172.21.64.1 icmp_seq=1 Time to live exceeded"
136+
// - "From 172.21.64.1: icmp_seq=1 Time to live exceeded"
135137
int addressStart = stdout.IndexOf("From ", StringComparison.Ordinal) + 5;
136-
int addressLength = stdout.IndexOf(' ', Math.Max(addressStart, 0)) - addressStart;
138+
int addressLength = stdout.AsSpan(Math.Max(addressStart, 0)).IndexOfAny(' ', ':');
137139
IPAddress? address;
138140
if (addressStart < 5 || addressLength <= 0 || !IPAddress.TryParse(stdout.AsSpan(addressStart, addressLength), out address))
139141
{

0 commit comments

Comments
 (0)