...
1
2
3
4
5
6
7 package ipv6
8
9 import (
10 "unsafe"
11
12 "golang.org/x/net/internal/iana"
13 "golang.org/x/net/internal/socket"
14
15 "golang.org/x/sys/unix"
16 )
17
18 func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
19 m := socket.ControlMessage(b)
20 m.MarshalHeader(iana.ProtocolIPv6, unix.IPV6_2292HOPLIMIT, 4)
21 if cm != nil {
22 socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
23 }
24 return m.Next(4)
25 }
26
27 func marshal2292PacketInfo(b []byte, cm *ControlMessage) []byte {
28 m := socket.ControlMessage(b)
29 m.MarshalHeader(iana.ProtocolIPv6, unix.IPV6_2292PKTINFO, sizeofInet6Pktinfo)
30 if cm != nil {
31 pi := (*inet6Pktinfo)(unsafe.Pointer(&m.Data(sizeofInet6Pktinfo)[0]))
32 if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
33 copy(pi.Addr[:], ip)
34 }
35 if cm.IfIndex > 0 {
36 pi.setIfindex(cm.IfIndex)
37 }
38 }
39 return m.Next(sizeofInet6Pktinfo)
40 }
41
42 func marshal2292NextHop(b []byte, cm *ControlMessage) []byte {
43 m := socket.ControlMessage(b)
44 m.MarshalHeader(iana.ProtocolIPv6, unix.IPV6_2292NEXTHOP, sizeofSockaddrInet6)
45 if cm != nil {
46 sa := (*sockaddrInet6)(unsafe.Pointer(&m.Data(sizeofSockaddrInet6)[0]))
47 sa.setSockaddr(cm.NextHop, cm.IfIndex)
48 }
49 return m.Next(sizeofSockaddrInet6)
50 }
51
View as plain text