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,10 +118,12 @@ func interfaceAddrTable(ifindex int) ([]Addr, error) { ...@@ -118,10 +118,12 @@ func interfaceAddrTable(ifindex int) ([]Addr, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if ifa != nil {
ifat = append(ifat, ifa) ifat = append(ifat, ifa)
} }
} }
} }
}
return ifat, nil return ifat, nil
} }
...@@ -157,6 +159,8 @@ func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) { ...@@ -157,6 +159,8 @@ func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
ifa.IP[2], ifa.IP[3] = 0, 0 ifa.IP[2], ifa.IP[3] = 0, 0
} }
} }
default: // Sockaddrs contain syscall.SockaddrDatalink on NetBSD
return nil, nil
} }
} }
return ifa, nil return ifa, nil
......
...@@ -75,9 +75,13 @@ func testInterfaceMulticastAddrs(t *testing.T, ifi *Interface) { ...@@ -75,9 +75,13 @@ func testInterfaceMulticastAddrs(t *testing.T, ifi *Interface) {
func testAddrs(t *testing.T, ifat []Addr) { func testAddrs(t *testing.T, ifat []Addr) {
for _, ifa := range ifat { for _, ifa := range ifat {
switch ifa.(type) { switch v := ifa.(type) {
case *IPAddr, *IPNet: case *IPAddr, *IPNet:
if v == nil {
t.Errorf("\tunexpected value: %v", ifa)
} else {
t.Logf("\tinterface address %q", ifa.String()) t.Logf("\tinterface address %q", ifa.String())
}
default: default:
t.Errorf("\tunexpected type: %T", ifa) t.Errorf("\tunexpected type: %T", ifa)
} }
...@@ -86,9 +90,13 @@ func testAddrs(t *testing.T, ifat []Addr) { ...@@ -86,9 +90,13 @@ func testAddrs(t *testing.T, ifat []Addr) {
func testMulticastAddrs(t *testing.T, ifmat []Addr) { func testMulticastAddrs(t *testing.T, ifmat []Addr) {
for _, ifma := range ifmat { for _, ifma := range ifmat {
switch ifma.(type) { switch v := ifma.(type) {
case *IPAddr: case *IPAddr:
if v == nil {
t.Errorf("\tunexpected value: %v", ifma)
} else {
t.Logf("\tjoined group address %q", ifma.String()) t.Logf("\tjoined group address %q", ifma.String())
}
default: default:
t.Errorf("\tunexpected type: %T", ifma) 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