blob: 25f6847f99a7cb25e7cc9043196e874cc28f6432 [file] [log] [blame]
Mikio Harab8b13432017-03-16 05:58:54 +09001// 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
Russ Cox5f55cee2021-02-19 18:54:43 -05005//go:build aix || darwin || dragonfly || freebsd || netbsd || openbsd
chigotc457ff442019-04-03 13:53:35 +02006// +build aix darwin dragonfly freebsd netbsd openbsd
Mikio Harab8b13432017-03-16 05:58:54 +09007
8package socket
9
10import "unsafe"
11
12func (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
27func (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
34func (h *msghdr) controllen() int {
35 return int(h.Controllen)
36}
37
38func (h *msghdr) flags() int {
39 return int(h.Flags)
40}