Source file
src/net/interface_darwin.go
1
2
3
4
5 package net
6
7 import (
8 "internal/routebsd"
9 "syscall"
10 )
11
12 func interfaceMessages(ifindex int) ([]routebsd.Message, error) {
13 return routebsd.FetchRIBMessages(syscall.NET_RT_IFLIST, ifindex)
14 }
15
16
17
18 func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
19 msgs, err := routebsd.FetchRIBMessages(syscall.NET_RT_IFLIST2, ifi.Index)
20 if err != nil {
21 return nil, err
22 }
23 ifmat := make([]Addr, 0, len(msgs))
24 for _, m := range msgs {
25 switch m := m.(type) {
26 case *routebsd.InterfaceMulticastAddrMessage:
27 if ifi.Index != m.Index {
28 continue
29 }
30 var ip IP
31 switch sa := m.Addrs[syscall.RTAX_IFA].(type) {
32 case *routebsd.InetAddr:
33 if sa.IP.Is4() {
34 a := sa.IP.As4()
35 ip = IPv4(a[0], a[1], a[2], a[3])
36 } else if sa.IP.Is6() {
37 a := sa.IP.As16()
38 ip = make(IP, IPv6len)
39 copy(ip, a[:])
40 }
41 }
42 if ip != nil {
43 ifmat = append(ifmat, &IPAddr{IP: ip})
44 }
45 }
46 }
47 return ifmat, nil
48 }
49
View as plain text