msghdr_linux.go 740 B

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