github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/ipv4/control_bsd.go (about) 1 // Copyright 2012 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 aix darwin dragonfly freebsd netbsd openbsd 6 7 package ipv4 8 9 import ( 10 "net" 11 "syscall" 12 "unsafe" 13 14 "golang.org/x/net/internal/iana" 15 "golang.org/x/net/internal/socket" 16 ) 17 18 func marshalDst(b []byte, cm *ControlMessage) []byte { 19 m := socket.ControlMessage(b) 20 m.MarshalHeader(iana.ProtocolIP, sysIP_RECVDSTADDR, net.IPv4len) 21 return m.Next(net.IPv4len) 22 } 23 24 func parseDst(cm *ControlMessage, b []byte) { 25 if len(cm.Dst) < net.IPv4len { 26 cm.Dst = make(net.IP, net.IPv4len) 27 } 28 copy(cm.Dst, b[:net.IPv4len]) 29 } 30 31 func marshalInterface(b []byte, cm *ControlMessage) []byte { 32 m := socket.ControlMessage(b) 33 m.MarshalHeader(iana.ProtocolIP, sysIP_RECVIF, syscall.SizeofSockaddrDatalink) 34 return m.Next(syscall.SizeofSockaddrDatalink) 35 } 36 37 func parseInterface(cm *ControlMessage, b []byte) { 38 var sadl syscall.SockaddrDatalink 39 copy((*[unsafe.Sizeof(sadl)]byte)(unsafe.Pointer(&sadl))[:], b) 40 cm.IfIndex = int(sadl.Index) 41 }