diff --git a/src/pkg/net/interface_test.go b/src/pkg/net/interface_test.go index 17b28b6456..efabb5f3c2 100644 --- a/src/pkg/net/interface_test.go +++ b/src/pkg/net/interface_test.go @@ -109,14 +109,14 @@ func testAddrs(t *testing.T, ifat []Addr) { for _, ifa := range ifat { switch ifa := ifa.(type) { case *IPAddr: - if ifa == nil { - t.Errorf("\tunexpected value: %v", ifa) + if ifa == nil || ifa.IP == nil { + t.Errorf("\tunexpected value: %v, %v", ifa, ifa.IP) } else { t.Logf("\tinterface address %q", ifa.String()) } case *IPNet: - if ifa == nil { - t.Errorf("\tunexpected value: %v", ifa) + if ifa == nil || ifa.IP == nil || ifa.Mask == nil { + t.Errorf("\tunexpected value: %v, %v, %v", ifa, ifa.IP, ifa.Mask) } else { _, prefixLen := ifa.Mask.Size() if ifa.IP.To4() != nil && prefixLen != 8*IPv4len || ifa.IP.To16() != nil && ifa.IP.To4() == nil && prefixLen != 8*IPv6len { diff --git a/src/pkg/syscall/route_bsd.go b/src/pkg/syscall/route_bsd.go index 103aa20f59..638073592d 100644 --- a/src/pkg/syscall/route_bsd.go +++ b/src/pkg/syscall/route_bsd.go @@ -13,10 +13,14 @@ import "unsafe" // Round the length of a raw sockaddr up to align it properly. func rsaAlignOf(salen int) int { salign := sizeofPtr - // NOTE: It seems like 64-bit Darwin kernel still requires 32-bit - // aligned access to BSD subsystem. - if darwinAMD64 { + // NOTE: It seems like 64-bit Darwin kernel still requires + // 32-bit aligned access to BSD subsystem. Also NetBSD 6 + // kernel and beyond require 64-bit aligned access to routing + // facilities. + if darwin64Bit { salign = 4 + } else if netbsd32Bit { + salign = 8 } if salen == 0 { return salign @@ -142,6 +146,12 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) { return nil } b := m.Data[:] + // We still see AF_UNSPEC in socket addresses on some + // platforms. To identify each address family correctly, we + // will use the address family of RTAX_NETMASK as a preferred + // one on the 32-bit NetBSD kernel, also use the length of + // RTAX_NETMASK socket address on the FreeBSD kernel. + preferredFamily := uint8(AF_UNSPEC) for i := uint(0); i < RTAX_MAX; i++ { if m.Header.Addrs&rtaIfaMask&(1<