Skip to content

Commit 1da4ad4

Browse files
Fix parsing the output of ping on Samsung phones (#80133)
* Account for different formats of ping output * Avoid allocation
1 parent 21af7c4 commit 1da4ad4

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
@@ -133,9 +133,11 @@ private static bool TryParseTtlExceeded(string stdout, out PingReply? reply)
133133
return false;
134134
}
135135

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

0 commit comments

Comments
 (0)