mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
netutils: minor cleanups
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
888e75dfc9
commit
ff141d366f
2 changed files with 5 additions and 9 deletions
|
@ -72,8 +72,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var addrs4 []net.Addr
|
||||
var addrs6 []net.Addr
|
||||
var addrs4, addrs6 []net.Addr
|
||||
for _, addr := range addrs {
|
||||
ip := (addr.(*net.IPNet)).IP
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
|
@ -84,7 +83,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
|
|||
}
|
||||
switch {
|
||||
case len(addrs4) == 0:
|
||||
return nil, nil, fmt.Errorf("Interface %v has no IPv4 addresses", name)
|
||||
return nil, nil, fmt.Errorf("interface %v has no IPv4 addresses", name)
|
||||
case len(addrs4) > 1:
|
||||
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
|
||||
name, (addrs4[0].(*net.IPNet)).IP)
|
||||
|
@ -173,9 +172,9 @@ func ParseAlias(val string) (string, string, error) {
|
|||
if val == "" {
|
||||
return "", "", errors.New("empty string specified for alias")
|
||||
}
|
||||
arr := strings.Split(val, ":")
|
||||
arr := strings.SplitN(val, ":", 3)
|
||||
if len(arr) > 2 {
|
||||
return "", "", fmt.Errorf("bad format for alias: %s", val)
|
||||
return "", "", errors.New("bad format for alias: " + val)
|
||||
}
|
||||
if len(arr) == 1 {
|
||||
return val, val, nil
|
||||
|
|
|
@ -69,10 +69,7 @@ func GenerateIfaceName(nlh *netlink.Handle, prefix string, len int) (string, err
|
|||
// list the first IPv4 address which does not conflict with other
|
||||
// interfaces on the system.
|
||||
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
|
||||
var (
|
||||
v4Nets []*net.IPNet
|
||||
v6Nets []*net.IPNet
|
||||
)
|
||||
var v4Nets, v6Nets []*net.IPNet
|
||||
|
||||
defer osl.InitOSContext()()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue