testsuite: fix g++.dg/tree-ssa/pr58483.C
[official-gcc.git] / libgo / go / net / interface_darwin.go
blobbb4fd73a987670bca842c0783d84c03324c3e41d
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.
5 package net
7 import (
8 "syscall"
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)
15 if err != nil {
16 return nil, err
18 return route.ParseRIB(syscall.NET_RT_IFLIST, rib)
21 // interfaceMulticastAddrTable returns addresses for a specific
22 // interface.
23 func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
24 rib, err := route.FetchRIB(syscall.AF_UNSPEC, syscall.NET_RT_IFLIST2, ifi.Index)
25 if err != nil {
26 return nil, err
28 msgs, err := route.ParseRIB(syscall.NET_RT_IFLIST2, rib)
29 if err != nil {
30 return nil, err
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 {
37 continue
39 var ip IP
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)
45 copy(ip, sa.IP[:])
47 if ip != nil {
48 ifmat = append(ifmat, &IPAddr{IP: ip})
52 return ifmat, nil