1
// Copyright 2013 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 linux netbsd openbsd
13
"golang.org/x/net/internal/iana"
16
func marshalTrafficClass(b []byte, cm *ControlMessage) []byte {
17
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
18
m.Level = iana.ProtocolIPv6
19
m.Type = sysIPV6_TCLASS
20
m.SetLen(syscall.CmsgLen(4))
22
data := b[syscall.CmsgLen(0):]
23
// TODO(mikio): fix potential misaligned memory access
24
*(*int32)(unsafe.Pointer(&data[:4][0])) = int32(cm.TrafficClass)
26
return b[syscall.CmsgSpace(4):]
29
func parseTrafficClass(cm *ControlMessage, b []byte) {
30
// TODO(mikio): fix potential misaligned memory access
31
cm.TrafficClass = int(*(*int32)(unsafe.Pointer(&b[:4][0])))
34
func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
35
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
36
m.Level = iana.ProtocolIPv6
37
m.Type = sysIPV6_HOPLIMIT
38
m.SetLen(syscall.CmsgLen(4))
40
data := b[syscall.CmsgLen(0):]
41
// TODO(mikio): fix potential misaligned memory access
42
*(*int32)(unsafe.Pointer(&data[:4][0])) = int32(cm.HopLimit)
44
return b[syscall.CmsgSpace(4):]
47
func parseHopLimit(cm *ControlMessage, b []byte) {
48
// TODO(mikio): fix potential misaligned memory access
49
cm.HopLimit = int(*(*int32)(unsafe.Pointer(&b[:4][0])))
52
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
53
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
54
m.Level = iana.ProtocolIPv6
55
m.Type = sysIPV6_PKTINFO
56
m.SetLen(syscall.CmsgLen(sysSizeofInet6Pktinfo))
58
pi := (*sysInet6Pktinfo)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
59
if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
63
pi.setIfindex(cm.IfIndex)
66
return b[syscall.CmsgSpace(sysSizeofInet6Pktinfo):]
69
func parsePacketInfo(cm *ControlMessage, b []byte) {
70
pi := (*sysInet6Pktinfo)(unsafe.Pointer(&b[0]))
72
cm.IfIndex = int(pi.Ifindex)
75
func marshalNextHop(b []byte, cm *ControlMessage) []byte {
76
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
77
m.Level = iana.ProtocolIPv6
78
m.Type = sysIPV6_NEXTHOP
79
m.SetLen(syscall.CmsgLen(sysSizeofSockaddrInet6))
81
sa := (*sysSockaddrInet6)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
82
sa.setSockaddr(cm.NextHop, cm.IfIndex)
84
return b[syscall.CmsgSpace(sysSizeofSockaddrInet6):]
87
func parseNextHop(cm *ControlMessage, b []byte) {
90
func marshalPathMTU(b []byte, cm *ControlMessage) []byte {
91
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
92
m.Level = iana.ProtocolIPv6
93
m.Type = sysIPV6_PATHMTU
94
m.SetLen(syscall.CmsgLen(sysSizeofIPv6Mtuinfo))
95
return b[syscall.CmsgSpace(sysSizeofIPv6Mtuinfo):]
98
func parsePathMTU(cm *ControlMessage, b []byte) {
99
mi := (*sysIPv6Mtuinfo)(unsafe.Pointer(&b[0]))
100
cm.Dst = mi.Addr.Addr[:]
101
cm.IfIndex = int(mi.Addr.Scope_id)