github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/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 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  )
    16  
    17  func marshalDst(b []byte, cm *ControlMessage) []byte {
    18  	m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
    19  	m.Level = iana.ProtocolIP
    20  	m.Type = sysIP_RECVDSTADDR
    21  	m.SetLen(syscall.CmsgLen(net.IPv4len))
    22  	return b[syscall.CmsgSpace(net.IPv4len):]
    23  }
    24  
    25  func parseDst(cm *ControlMessage, b []byte) {
    26  	cm.Dst = b[:net.IPv4len]
    27  }
    28  
    29  func marshalInterface(b []byte, cm *ControlMessage) []byte {
    30  	m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
    31  	m.Level = iana.ProtocolIP
    32  	m.Type = sysIP_RECVIF
    33  	m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
    34  	return b[syscall.CmsgSpace(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  }