gcc/ChangeLog:
[official-gcc.git] / libgo / go / syscall / route_ifma_test.go
blobaf2b67dc24492e2f68814c0e55a19112a49195d0
1 // Copyright 2015 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 // +build darwin dragonfly freebsd
7 package syscall_test
9 import (
10 "fmt"
11 "syscall"
14 func parseRoutingMessageHeader(m syscall.RoutingMessage) (addrFlags, error) {
15 switch m := m.(type) {
16 case *syscall.RouteMessage:
17 errno := syscall.Errno(uintptr(m.Header.Errno))
18 if errno != 0 {
19 return 0, fmt.Errorf("%T: %v, %#v", m, errno, m.Header)
21 return addrFlags(m.Header.Addrs), nil
22 case *syscall.InterfaceMessage:
23 return addrFlags(m.Header.Addrs), nil
24 case *syscall.InterfaceAddrMessage:
25 return addrFlags(m.Header.Addrs), nil
26 case *syscall.InterfaceMulticastAddrMessage:
27 return addrFlags(m.Header.Addrs), nil
28 default:
29 panic(fmt.Sprintf("unknown routing message type: %T", m))
33 func parseRoutingSockaddrs(m syscall.RoutingMessage) ([]syscall.Sockaddr, error) {
34 switch m := m.(type) {
35 case *syscall.RouteMessage:
36 sas, err := syscall.ParseRoutingSockaddr(m)
37 if err != nil {
38 return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
40 if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
41 return nil, err
43 return sas, nil
44 case *syscall.InterfaceMessage:
45 sas, err := syscall.ParseRoutingSockaddr(m)
46 if err != nil {
47 return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
49 if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
50 return nil, err
52 return sas, nil
53 case *syscall.InterfaceAddrMessage:
54 sas, err := syscall.ParseRoutingSockaddr(m)
55 if err != nil {
56 return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
58 if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
59 return nil, err
61 return sas, nil
62 case *syscall.InterfaceMulticastAddrMessage:
63 sas, err := syscall.ParseRoutingSockaddr(m)
64 if err != nil {
65 return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
67 if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
68 return nil, err
70 return sas, nil
71 default:
72 panic(fmt.Sprintf("unknown routing message type: %T", m))