MCPcopy Create free account
hub / github.com/ddev/ddev / HasLocalIP

Function HasLocalIP

pkg/netutil/netutil.go:79–107  ·  view source on GitHub ↗

HasLocalIP returns true if at least one of the provided IP addresses is assigned to the local computer

(ipAddresses []net.IP)

Source from the content-addressed store, hash-verified

77// HasLocalIP returns true if at least one of the provided IP addresses is
78// assigned to the local computer
79func 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
110func GetLocalIPs() ([]string, error) {

Callers 1

Calls 3

GetDockerIPFunction · 0.92
WarningFunction · 0.92
GetLocalIPsFunction · 0.85

Tested by

no test coverage detected