From 182f881d821e2b1d0eb64b4fa25888f50edebc42 Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Thu, 16 Jul 2015 22:24:47 -0400 Subject: [PATCH] Fixes #1099 by raising an error when we multiple private IPs are found --- consul/util.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/consul/util.go b/consul/util.go index 6cc7858995..d3cb1eb8e6 100644 --- a/consul/util.go +++ b/consul/util.go @@ -161,6 +161,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 @@ -179,11 +181,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