mirror of
https://github.com/minio/minio.git
synced 2025-11-21 10:16:03 -05:00
Use net.ParseCIDR instead of custom-built parsers (#3055)
Removes avoidable conversion to and from net.IP to string.
This commit is contained in:
committed by
Harshavardhana
parent
35e541e0b1
commit
49ba07d1d6
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user