HasLocalIP returns true if at least one of the provided IP addresses is assigned to the local computer
(ipAddresses []net.IP)
| 77 | // HasLocalIP returns true if at least one of the provided IP addresses is |
| 78 | // assigned to the local computer |
| 79 | func HasLocalIP(ipAddresses []net.IP) bool { |
| 80 | dockerIP, err := dockerutil.GetDockerIP() |
| 81 | |
| 82 | if err != nil { |
| 83 | util.Warning("Failed to get Docker IP address: %v", err) |
| 84 | return false |
| 85 | } |
| 86 | |
| 87 | for _, ipAddress := range ipAddresses { |
| 88 | if ipAddress.String() == dockerIP { |
| 89 | return true |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | localIPs, err := GetLocalIPs() |
| 94 | |
| 95 | if err != nil { |
| 96 | util.Warning("Failed to get local IPs: %v", err) |
| 97 | return false |
| 98 | } |
| 99 | |
| 100 | // Check if the parsed IP address is local using slices.Contains |
| 101 | for _, ipAddress := range ipAddresses { |
| 102 | if slices.Contains(localIPs, ipAddress.String()) { |
| 103 | return true |
| 104 | } |
| 105 | } |
| 106 | return false |
| 107 | } |
| 108 | |
| 109 | // GetLocalIPs returns IP addresses associated with the machine |
| 110 | func GetLocalIPs() ([]string, error) { |
no test coverage detected