Commit 12e7397e authored by Mikio Hara's avatar Mikio Hara

net: don't return nil interface address on netbsd

On NetBSD routing sockaddrs for interface address contain sockaddr_dl.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/7085064
parent 9114279c
......@@ -118,7 +118,9 @@ func interfaceAddrTable(ifindex int) ([]Addr, error) {
if err != nil {
return nil, err
}
ifat = append(ifat, ifa)
if ifa != nil {
ifat = append(ifat, ifa)
}
}
}
}
......@@ -157,6 +159,8 @@ func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
ifa.IP[2], ifa.IP[3] = 0, 0
}
}
default: // Sockaddrs contain syscall.SockaddrDatalink on NetBSD
return nil, nil
}
}
return ifa, nil
......
......@@ -75,9 +75,13 @@ func testInterfaceMulticastAddrs(t *testing.T, ifi *Interface) {
func testAddrs(t *testing.T, ifat []Addr) {
for _, ifa := range ifat {
switch ifa.(type) {
switch v := ifa.(type) {
case *IPAddr, *IPNet:
t.Logf("\tinterface address %q", ifa.String())
if v == nil {
t.Errorf("\tunexpected value: %v", ifa)
} else {
t.Logf("\tinterface address %q", ifa.String())
}
default:
t.Errorf("\tunexpected type: %T", ifa)
}
......@@ -86,9 +90,13 @@ func testAddrs(t *testing.T, ifat []Addr) {
func testMulticastAddrs(t *testing.T, ifmat []Addr) {
for _, ifma := range ifmat {
switch ifma.(type) {
switch v := ifma.(type) {
case *IPAddr:
t.Logf("\tjoined group address %q", ifma.String())
if v == nil {
t.Errorf("\tunexpected value: %v", ifma)
} else {
t.Logf("\tjoined group address %q", ifma.String())
}
default:
t.Errorf("\tunexpected type: %T", ifma)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment