github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/ipv6/control_rfc2292_unix.go (about)

     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.
     4  
     5  // +build darwin
     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  
    16  func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
    17  	m := socket.ControlMessage(b)
    18  	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4)
    19  	if cm != nil {
    20  		socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
    21  	}
    22  	return m.Next(4)
    23  }
    24  
    25  func marshal2292PacketInfo(b []byte, cm *ControlMessage) []byte {
    26  	m := socket.ControlMessage(b)
    27  	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292PKTINFO, sizeofInet6Pktinfo)
    28  	if cm != nil {
    29  		pi := (*inet6Pktinfo)(unsafe.Pointer(&m.Data(sizeofInet6Pktinfo)[0]))
    30  		if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
    31  			copy(pi.Addr[:], ip)
    32  		}
    33  		if cm.IfIndex > 0 {
    34  			pi.setIfindex(cm.IfIndex)
    35  		}
    36  	}
    37  	return m.Next(sizeofInet6Pktinfo)
    38  }
    39  
    40  func marshal2292NextHop(b []byte, cm *ControlMessage) []byte {
    41  	m := socket.ControlMessage(b)
    42  	m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292NEXTHOP, sizeofSockaddrInet6)
    43  	if cm != nil {
    44  		sa := (*sockaddrInet6)(unsafe.Pointer(&m.Data(sizeofSockaddrInet6)[0]))
    45  		sa.setSockaddr(cm.NextHop, cm.IfIndex)
    46  	}
    47  	return m.Next(sizeofSockaddrInet6)
    48  }