windowsPingOutputIsSuccess reports whether the ping.exe output b contains a success ping response for ip. See https://github.com/tailscale/tailscale/issues/13654 TODO(bradfitz,nickkhyl): delete this and use the proper Windows APIs.
(ip netip.Addr, b []byte)
| 2349 | // |
| 2350 | // TODO(bradfitz,nickkhyl): delete this and use the proper Windows APIs. |
| 2351 | func windowsPingOutputIsSuccess(ip netip.Addr, b []byte) bool { |
| 2352 | // Look for a line that contains " <ip>: " and then three equal signs. |
| 2353 | // As a special case, the 2nd equal sign may be a '<' character |
| 2354 | // for sub-millisecond pings. |
| 2355 | // This heuristic seems to match the ping.exe output in any language. |
| 2356 | sub := fmt.Appendf(nil, " %s: ", ip) |
| 2357 | |
| 2358 | eqSigns := func(bb []byte) (n int) { |
| 2359 | for _, b := range bb { |
| 2360 | if b == '=' || (b == '<' && n == 1) { |
| 2361 | n++ |
| 2362 | } |
| 2363 | } |
| 2364 | return |
| 2365 | } |
| 2366 | |
| 2367 | for len(b) > 0 { |
| 2368 | var line []byte |
| 2369 | line, b, _ = bytes.Cut(b, []byte("\n")) |
| 2370 | if _, rest, ok := bytes.Cut(line, sub); ok && eqSigns(rest) == 3 { |
| 2371 | return true |
| 2372 | } |
| 2373 | } |
| 2374 | return false |
| 2375 | } |
no outgoing calls
searching dependent graphs…