golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/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 //go: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 "golang.org/x/sys/unix" 18 ) 19 20 func marshalDst(b []byte, cm *ControlMessage) []byte { 21 m := socket.ControlMessage(b) 22 m.MarshalHeader(iana.ProtocolIP, unix.IP_RECVDSTADDR, net.IPv4len) 23 return m.Next(net.IPv4len) 24 } 25 26 func parseDst(cm *ControlMessage, b []byte) { 27 if len(cm.Dst) < net.IPv4len { 28 cm.Dst = make(net.IP, net.IPv4len) 29 } 30 copy(cm.Dst, b[:net.IPv4len]) 31 } 32 33 func marshalInterface(b []byte, cm *ControlMessage) []byte { 34 m := socket.ControlMessage(b) 35 m.MarshalHeader(iana.ProtocolIP, sockoptReceiveInterface, syscall.SizeofSockaddrDatalink) 36 return m.Next(syscall.SizeofSockaddrDatalink) 37 } 38 39 func parseInterface(cm *ControlMessage, b []byte) { 40 var sadl syscall.SockaddrDatalink 41 copy((*[unsafe.Sizeof(sadl)]byte)(unsafe.Pointer(&sadl))[:], b) 42 cm.IfIndex = int(sadl.Index) 43 }