]> Cypherpunks repositories - gostls13.git/commitdiff
net: don't return nil interface address on netbsd
authorMikio Hara <mikioh.mikioh@gmail.com>
Tue, 22 Jan 2013 22:11:22 +0000 (07:11 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Tue, 22 Jan 2013 22:11:22 +0000 (07:11 +0900)
On NetBSD routing sockaddrs for interface address contain sockaddr_dl.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/7085064

src/pkg/net/interface_bsd.go
src/pkg/net/interface_test.go

index 7f090d8d40699323f6dc590866312bd073e38e0a..df9b3a2f279a4759e07f61c51a741c6019462b67 100644 (file)
@@ -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
index 2fe0f60caeac0e5cd446e25c433612eb79023bfb..803c1f4495ca1bb7481a5c8fb344ded58ff98eef 100644 (file)
@@ -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)
                }