add a fallback to an ipv4 address if the the range can't find one
This commit is contained in:
parent
aaf9103330
commit
7fc2ea8422
|
@ -43,6 +43,7 @@ func getHostIP(s string, network *net.IPNet) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
// look for an IP that is contained in the ip_wait_address range
|
||||
for _, a := range addrs {
|
||||
ipnet, ok := a.(*net.IPNet)
|
||||
if ok && !ipnet.IP.IsLoopback() {
|
||||
|
@ -51,5 +52,15 @@ func getHostIP(s string, network *net.IPNet) (string, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to an ipv4 address if an IP is not found in the range
|
||||
for _, a := range addrs {
|
||||
ipnet, ok := a.(*net.IPNet)
|
||||
if ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("IP not found")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue