sockcmsg_unix_other.go 954 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 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 freebsd linux netbsd openbsd solaris
  5. package unix
  6. import (
  7. "runtime"
  8. )
  9. // Round the length of a raw sockaddr up to align it properly.
  10. func cmsgAlignOf(salen int) int {
  11. salign := SizeofPtr
  12. // dragonfly needs to check ABI version at runtime, see cmsgAlignOf in
  13. // sockcmsg_dragonfly.go
  14. switch runtime.GOOS {
  15. case "aix":
  16. // There is no alignment on AIX.
  17. salign = 1
  18. case "darwin", "illumos", "solaris":
  19. // NOTE: It seems like 64-bit Darwin, Illumos and Solaris
  20. // kernels still require 32-bit aligned access to network
  21. // subsystem.
  22. if SizeofPtr == 8 {
  23. salign = 4
  24. }
  25. case "netbsd", "openbsd":
  26. // NetBSD and OpenBSD armv7 require 64-bit alignment.
  27. if runtime.GOARCH == "arm" {
  28. salign = 8
  29. }
  30. }
  31. return (salen + salign - 1) & ^(salign - 1)
  32. }