Bind to loopback only as last resort

This commit is contained in:
William Tisäter 2015-09-02 12:24:44 +02:00
parent 1013f2f494
commit 4ce2af3bd4

View file

@ -178,6 +178,7 @@ func isPrivateIP(ip_str string) bool {
// Returns addresses from interfaces that is up
func activeInterfaceAddresses() ([]net.Addr, error) {
var upAddrs []net.Addr
var loAddrs []net.Addr
interfaces, err := net.Interfaces()
if err != nil {
@ -195,9 +196,18 @@ func activeInterfaceAddresses() ([]net.Addr, error) {
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
}
if iface.Flags&net.FlagLoopback != 0 {
loAddrs = append(loAddrs, addresses...)
continue
}
upAddrs = append(upAddrs, addresses...)
}
if len(upAddrs) == 0 {
return loAddrs, nil
}
return upAddrs, nil
}