mirror of https://github.com/status-im/consul.git
command/agent: find proper private IP on Windows
/cc @armon
This commit is contained in:
parent
03a98ed1d7
commit
78b7c57ba3
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,21 +1,20 @@
|
|||
## 0.2.1 (unreleased)
|
||||
|
||||
FEATURES:
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* Renaming "seperator" to "separator". This is the correct spelling,
|
||||
but both spellings are respected for backwards compatibility. [GH-101]
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
* Improved the URL formatting for the key/value editor in the Web UI.
|
||||
Importantly, the editor now allows editing keys with dashes in the
|
||||
name. [GH-119]
|
||||
Importantly, the editor now allows editing keys with dashes in the
|
||||
name. [GH-119]
|
||||
* The web UI now has cancel and delete folder actions in the key/value
|
||||
editor. [GH-124], [GH-122]
|
||||
editor. [GH-124], [GH-122]
|
||||
* Add flag to agent to write pid to a file. [GH-106]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* Renaming "seperator" to "separator". This is the correct spelling,
|
||||
but both spellings are respected for backwards compatibility. [GH-101]
|
||||
* Private IP is properly found on Windows clients.
|
||||
|
||||
## 0.2.0 (May 1, 2014)
|
||||
|
||||
FEATURES:
|
||||
|
|
|
@ -79,7 +79,7 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get advertise address: %v", err)
|
||||
}
|
||||
config.AdvertiseAddr = ip.IP.String()
|
||||
config.AdvertiseAddr = ip.String()
|
||||
}
|
||||
|
||||
agent := &Agent{
|
||||
|
|
|
@ -106,26 +106,34 @@ func isPrivateIP(ip_str string) bool {
|
|||
|
||||
// GetPrivateIP is used to return the first private IP address
|
||||
// associated with an interface on the machine
|
||||
func GetPrivateIP() (*net.IPNet, error) {
|
||||
func GetPrivateIP() (net.IP, error) {
|
||||
addresses, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get interface addresses: %v", err)
|
||||
}
|
||||
|
||||
// Find private IPv4 address
|
||||
for _, addr := range addresses {
|
||||
ip, ok := addr.(*net.IPNet)
|
||||
if !ok {
|
||||
for _, rawAddr := range addresses {
|
||||
var ip net.IP
|
||||
switch addr := rawAddr.(type) {
|
||||
case *net.IPAddr:
|
||||
ip = addr.IP
|
||||
case *net.IPNet:
|
||||
ip = addr.IP
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if ip.IP.To4() == nil {
|
||||
|
||||
if ip.To4() == nil {
|
||||
continue
|
||||
}
|
||||
if !isPrivateIP(ip.IP.String()) {
|
||||
if !isPrivateIP(ip.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("No private IP address found")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue