mirror of
https://github.com/containers/podman.git
synced 2025-12-04 20:28:40 +08:00
vendor: update c/common to latest
To include new pasta package Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
22
vendor/github.com/containers/common/libnetwork/util/ip.go
generated
vendored
22
vendor/github.com/containers/common/libnetwork/util/ip.go
generated
vendored
@@ -54,3 +54,25 @@ func NormalizeIP(ip *net.IP) {
|
||||
*ip = ipv4
|
||||
}
|
||||
}
|
||||
|
||||
// GetLocalIP returns the first non loopback local IPv4 of the host.
|
||||
// If no ipv4 address is found it may return an ipv6 address.
|
||||
// When no ip is found and empty string is returned.
|
||||
func GetLocalIP() string {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
ip := ""
|
||||
for _, address := range addrs {
|
||||
// check the address type and if it is not a loopback the display it
|
||||
if ipnet, ok := address.(*net.IPNet); ok && ipnet.IP.IsGlobalUnicast() {
|
||||
if IsIPv4(ipnet.IP) {
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
// if ipv6 we keep looking for an ipv4 address
|
||||
ip = ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user