MCPcopy
hub / github.com/cloudflare/cloudflared / getLocalIPs

Function getLocalIPs

ingress/origin_icmp_proxy_test.go:392–413  ·  view source on GitHub ↗
(t *testing.T, ipv4 bool)

Source from the content-addressed store, hash-verified

390}
391
392func getLocalIPs(t *testing.T, ipv4 bool) []netip.Addr {
393 interfaces, err := net.Interfaces()
394 require.NoError(t, err)
395 localIPs := []netip.Addr{}
396 for _, i := range interfaces {
397 // Skip TUN devices, and Docker Networks
398 if strings.Contains(i.Name, "tun") || strings.Contains(i.Name, "docker") || strings.HasPrefix(i.Name, "br-") {
399 continue
400 }
401 addrs, err := i.Addrs()
402 require.NoError(t, err)
403 for _, addr := range addrs {
404 if ipnet, ok := addr.(*net.IPNet); ok && (ipnet.IP.IsPrivate() || ipnet.IP.IsLoopback()) {
405 // TODO DEVTOOLS-12514: We only run the IPv6 against the loopback interface due to issues on the CI runners.
406 if (ipv4 && ipnet.IP.To4() != nil) || (!ipv4 && ipnet.IP.To4() == nil && ipnet.IP.IsLoopback()) {
407 localIPs = append(localIPs, netip.MustParseAddr(ipnet.IP.String()))
408 }
409 }
410 }
411 }
412 return localIPs
413}

Callers 1

testICMPRouterEchoFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected