aboutsummaryrefslogtreecommitdiff
path: root/src/net/interface_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/interface_darwin.go')
-rw-r--r--src/net/interface_darwin.go37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/net/interface_darwin.go b/src/net/interface_darwin.go
index ad0937db04..475b8611ce 100644
--- a/src/net/interface_darwin.go
+++ b/src/net/interface_darwin.go
@@ -29,35 +29,34 @@ func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
if err != nil {
return nil, err
}
- ifmat = append(ifmat, ifma...)
+ if ifma != nil {
+ ifmat = append(ifmat, ifma)
+ }
}
}
}
return ifmat, nil
}
-func newMulticastAddr(ifi *Interface, m *syscall.InterfaceMulticastAddrMessage) ([]Addr, error) {
+func newMulticastAddr(ifi *Interface, m *syscall.InterfaceMulticastAddrMessage) (*IPAddr, error) {
sas, err := syscall.ParseRoutingSockaddr(m)
if err != nil {
return nil, os.NewSyscallError("route sockaddr", err)
}
- var ifmat []Addr
- for _, sa := range sas {
- switch sa := sa.(type) {
- case *syscall.SockaddrInet4:
- ifma := &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])}
- ifmat = append(ifmat, ifma.toAddr())
- case *syscall.SockaddrInet6:
- ifma := &IPAddr{IP: make(IP, IPv6len)}
- copy(ifma.IP, sa.Addr[:])
- // NOTE: KAME based IPv6 protocol stack usually embeds
- // the interface index in the interface-local or link-
- // local address as the kernel-internal form.
- if ifma.IP.IsInterfaceLocalMulticast() || ifma.IP.IsLinkLocalMulticast() {
- ifma.IP[2], ifma.IP[3] = 0, 0
- }
- ifmat = append(ifmat, ifma.toAddr())
+ switch sa := sas[syscall.RTAX_IFA].(type) {
+ case *syscall.SockaddrInet4:
+ return &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])}, nil
+ case *syscall.SockaddrInet6:
+ ifma := IPAddr{IP: make(IP, IPv6len)}
+ copy(ifma.IP, sa.Addr[:])
+ // NOTE: KAME based IPv6 protcol stack usually embeds
+ // the interface index in the interface-local or
+ // link-local address as the kernel-internal form.
+ if ifma.IP.IsInterfaceLocalMulticast() || ifma.IP.IsLinkLocalMulticast() {
+ ifma.IP[2], ifma.IP[3] = 0, 0
}
+ return &ifma, nil
+ default:
+ return nil, nil
}
- return ifmat, nil
}