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
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
))
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
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
)
38 return nil, fmt
.Errorf("%T: %v, %#v", m
, err
, m
.Data
)
40 if err
= sockaddrs(sas
).match(addrFlags(m
.Header
.Addrs
)); err
!= nil {
44 case *syscall
.InterfaceMessage
:
45 sas
, err
:= syscall
.ParseRoutingSockaddr(m
)
47 return nil, fmt
.Errorf("%T: %v, %#v", m
, err
, m
.Data
)
49 if err
= sockaddrs(sas
).match(addrFlags(m
.Header
.Addrs
)); err
!= nil {
53 case *syscall
.InterfaceAddrMessage
:
54 sas
, err
:= syscall
.ParseRoutingSockaddr(m
)
56 return nil, fmt
.Errorf("%T: %v, %#v", m
, err
, m
.Data
)
58 if err
= sockaddrs(sas
).match(addrFlags(m
.Header
.Addrs
)); err
!= nil {
62 case *syscall
.InterfaceMulticastAddrMessage
:
63 sas
, err
:= syscall
.ParseRoutingSockaddr(m
)
65 return nil, fmt
.Errorf("%T: %v, %#v", m
, err
, m
.Data
)
67 if err
= sockaddrs(sas
).match(addrFlags(m
.Header
.Addrs
)); err
!= nil {
72 panic(fmt
.Sprintf("unknown routing message type: %T", m
))