Use net.ParseCIDR instead of custom-built parsers (#3055)

Removes avoidable conversion to and from net.IP to string.
This commit is contained in:
Krishnan Parthasarathi
2016-10-24 15:13:16 +05:30
committed by Harshavardhana
parent 35e541e0b1
commit 49ba07d1d6
5 changed files with 105 additions and 150 deletions

View File

@@ -222,23 +222,14 @@ func getListenIPs(httpServerConf *http.Server) (hosts []string, port string, err
return nil, port, fmt.Errorf("Unable to parse host address %s", err)
}
if host == "" {
var addrs []net.Addr
addrs, err = net.InterfaceAddrs()
if err != nil {
return nil, port, fmt.Errorf("Unable to determine network interface address. %s", err)
}
for _, addr := range addrs {
if addr.Network() == "ip+net" {
hostname := strings.Split(addr.String(), "/")[0]
if ip := net.ParseIP(hostname); ip.To4() != nil {
hosts = append(hosts, hostname)
}
}
}
err = sortIPsByOctet(hosts)
var ipv4s []net.IP
ipv4s, err = getInterfaceIPv4s()
if err != nil {
return nil, port, fmt.Errorf("Unable reverse sorted ips from hosts %s", err)
}
for _, ip := range ipv4s {
hosts = append(hosts, ip.String())
}
return hosts, port, nil
} // if host != "" {
// Proceed to append itself, since user requested a specific endpoint.