msghdr_bsd.go 926 B

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