1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/net/route"
13 func interfaceMessages(ifindex
int) ([]route
.Message
, error
) {
14 rib
, err
:= route
.FetchRIB(syscall
.AF_UNSPEC
, syscall
.NET_RT_IFLIST
, ifindex
)
18 return route
.ParseRIB(syscall
.NET_RT_IFLIST
, rib
)
21 // interfaceMulticastAddrTable returns addresses for a specific
23 func interfaceMulticastAddrTable(ifi
*Interface
) ([]Addr
, error
) {
24 rib
, err
:= route
.FetchRIB(syscall
.AF_UNSPEC
, syscall
.NET_RT_IFLIST2
, ifi
.Index
)
28 msgs
, err
:= route
.ParseRIB(syscall
.NET_RT_IFLIST2
, rib
)
32 ifmat
:= make([]Addr
, 0, len(msgs
))
33 for _
, m
:= range msgs
{
34 switch m
:= m
.(type) {
35 case *route
.InterfaceMulticastAddrMessage
:
36 if ifi
.Index
!= m
.Index
{
40 switch sa
:= m
.Addrs
[syscall
.RTAX_IFA
].(type) {
41 case *route
.Inet4Addr
:
42 ip
= IPv4(sa
.IP
[0], sa
.IP
[1], sa
.IP
[2], sa
.IP
[3])
43 case *route
.Inet6Addr
:
44 ip
= make(IP
, IPv6len
)
48 ifmat
= append(ifmat
, &IPAddr
{IP
: ip
})