Skip to content

Commit

Permalink
Merge pull request #1119 from trumant/multiple_private_IPs
Browse files Browse the repository at this point in the history
Fixes #1099 by raising an error when we multiple private IPs are found
  • Loading branch information
armon committed Jul 23, 2015
2 parents 981c62c + 182f881 commit dcb5ae7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions consul/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func GetPrivateIP() (net.IP, error) {
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
}

var candidates []net.IP

// Find private IPv4 address
for _, rawAddr := range addresses {
var ip net.IP
Expand All @@ -187,11 +189,17 @@ func GetPrivateIP() (net.IP, error) {
if !isPrivateIP(ip.String()) {
continue
}

return ip, nil
candidates = append(candidates, ip)
}
numIps := len(candidates)
switch numIps {
case 0:
return nil, fmt.Errorf("No private IP address found")
case 1:
return candidates[0], nil
default:
return nil, fmt.Errorf("Multiple private IPs found. Please configure one.")
}

return nil, fmt.Errorf("No private IP address found")
}

// Converts bytes to an integer
Expand Down

0 comments on commit dcb5ae7

Please sign in to comment.