From 2a08cbaeb20f4750afbcdcc8519678461f731eda Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Thu, 1 Oct 2015 21:16:39 +0200 Subject: [PATCH] Refactored code. --- client/fingerprint/network_unix.go | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/client/fingerprint/network_unix.go b/client/fingerprint/network_unix.go index 0d8212ca8..b1592ce1d 100644 --- a/client/fingerprint/network_unix.go +++ b/client/fingerprint/network_unix.go @@ -154,22 +154,24 @@ func (f *NetworkFingerprint) nativeIpAddress(device string) (string, error) { // TODO: should we handle IPv6 here? How do we determine precedence? for _, i := range ifaces { - if i.Name == device { - addrs, err := i.Addrs() - if err != nil { - return "", errors.New("could not retrieve interface IP addresses") - } + if i.Name != device { + continue + } - for _, a := range addrs { - switch v := a.(type) { - case *net.IPNet: - if v.IP.To4() != nil { - ip = v.IP.String() - } - case *net.IPAddr: - if v.IP.To4() != nil { - ip = v.IP.String() - } + addrs, err := i.Addrs() + if err != nil { + return "", errors.New("could not retrieve interface IP addresses") + } + + for _, a := range addrs { + switch v := a.(type) { + case *net.IPNet: + if v.IP.To4() != nil { + ip = v.IP.String() + } + case *net.IPAddr: + if v.IP.To4() != nil { + ip = v.IP.String() } } }