gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/internal/socket/msghdr_bsd.go (about) 1 // Copyright 2017 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 // +build aix darwin dragonfly freebsd netbsd openbsd 7 8 package socket 9 10 import "unsafe" 11 12 func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) { 13 for i := range vs { 14 vs[i].set(bs[i]) 15 } 16 h.setIov(vs) 17 if len(oob) > 0 { 18 h.Control = (*byte)(unsafe.Pointer(&oob[0])) 19 h.Controllen = uint32(len(oob)) 20 } 21 if sa != nil { 22 h.Name = (*byte)(unsafe.Pointer(&sa[0])) 23 h.Namelen = uint32(len(sa)) 24 } 25 } 26 27 func (h *msghdr) name() []byte { 28 if h.Name != nil && h.Namelen > 0 { 29 return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen] 30 } 31 return nil 32 } 33 34 func (h *msghdr) controllen() int { 35 return int(h.Controllen) 36 } 37 38 func (h *msghdr) flags() int { 39 return int(h.Flags) 40 }