simplify interface IPv4 address parsing

This commit is contained in:
☸️ 2021-09-20 16:52:53 +10:00 committed by GitHub
commit e255eba69f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,7 +254,7 @@ func FindInterface(name string) (*Endpoint, error) {
// user did not provide an interface name, // user did not provide an interface name,
// return the first one with a valid ipv4 // return the first one with a valid ipv4
// address // address that does not loop back
for _, iface := range ifaces { for _, iface := range ifaces {
addrs, err := iface.Addrs() addrs, err := iface.Addrs()
if err != nil { if err != nil {
@ -264,7 +264,7 @@ func FindInterface(name string) (*Endpoint, error) {
for _, address := range addrs { for _, address := range addrs {
ip := address.String() ip := address.String()
if !strings.Contains(ip, "127.0.0.1") && IPv4Validator.MatchString(ip) { if ip != "127.0.0.1" && IPv4Validator.MatchString(ip) {
return buildEndpointFromInterface(iface) return buildEndpointFromInterface(iface)
} }
} }