msghdr_bsd.go 856 B

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