github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/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 "github.com/Andyfoo/golang/x/net/internal/iana" 15 "github.com/Andyfoo/golang/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 sadl := (*syscall.SockaddrDatalink)(unsafe.Pointer(&b[0])) 39 cm.IfIndex = int(sadl.Index) 40 }