blob: 5567afc88da40725b375eddce9c4cb0504132381 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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// +build darwin dragonfly freebsd netbsd openbsd
6
7package socket
8
9import "unsafe"
10
11func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
12 for i := range vs {
13 vs[i].set(bs[i])
14 }
15 h.setIov(vs)
16 if len(oob) > 0 {
17 h.Control = (*byte)(unsafe.Pointer(&oob[0]))
18 h.Controllen = uint32(len(oob))
19 }
20 if sa != nil {
21 h.Name = (*byte)(unsafe.Pointer(&sa[0]))
22 h.Namelen = uint32(len(sa))
23 }
24}
25
26func (h *msghdr) name() []byte {
27 if h.Name != nil && h.Namelen > 0 {
28 return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen]
29 }
30 return nil
31}
32
33func (h *msghdr) controllen() int {
34 return int(h.Controllen)
35}
36
37func (h *msghdr) flags() int {
38 return int(h.Flags)
39}