Skip to content

Commit ff141d3

Browse files
committed
netutils: minor cleanups
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 888e75d commit ff141d3

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

libnetwork/netutils/utils.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
7272
if err != nil {
7373
return nil, nil, err
7474
}
75-
var addrs4 []net.Addr
76-
var addrs6 []net.Addr
75+
var addrs4, addrs6 []net.Addr
7776
for _, addr := range addrs {
7877
ip := (addr.(*net.IPNet)).IP
7978
if ip4 := ip.To4(); ip4 != nil {
@@ -84,7 +83,7 @@ func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
8483
}
8584
switch {
8685
case len(addrs4) == 0:
87-
return nil, nil, fmt.Errorf("Interface %v has no IPv4 addresses", name)
86+
return nil, nil, fmt.Errorf("interface %v has no IPv4 addresses", name)
8887
case len(addrs4) > 1:
8988
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
9089
name, (addrs4[0].(*net.IPNet)).IP)
@@ -173,9 +172,9 @@ func ParseAlias(val string) (string, string, error) {
173172
if val == "" {
174173
return "", "", errors.New("empty string specified for alias")
175174
}
176-
arr := strings.Split(val, ":")
175+
arr := strings.SplitN(val, ":", 3)
177176
if len(arr) > 2 {
178-
return "", "", fmt.Errorf("bad format for alias: %s", val)
177+
return "", "", errors.New("bad format for alias: " + val)
179178
}
180179
if len(arr) == 1 {
181180
return val, val, nil

libnetwork/netutils/utils_linux.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func GenerateIfaceName(nlh *netlink.Handle, prefix string, len int) (string, err
6969
// list the first IPv4 address which does not conflict with other
7070
// interfaces on the system.
7171
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
72-
var (
73-
v4Nets []*net.IPNet
74-
v6Nets []*net.IPNet
75-
)
72+
var v4Nets, v6Nets []*net.IPNet
7673

7774
defer osl.InitOSContext()()
7875

0 commit comments

Comments
 (0)