sys_freebsd.go 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 (
  6. "syscall"
  7. "unsafe"
  8. )
  9. func probeProtocolStack() int {
  10. var p uintptr
  11. align := int(unsafe.Sizeof(p))
  12. // In the case of kern.supported_archs="amd64 i386", we need
  13. // to know the underlying kernel's architecture because the
  14. // alignment for socket facilities are set at the build time
  15. // of the kernel.
  16. conf, _ := syscall.Sysctl("kern.conftxt")
  17. for i, j := 0, 0; j < len(conf); j++ {
  18. if conf[j] != '\n' {
  19. continue
  20. }
  21. s := conf[i:j]
  22. i = j + 1
  23. if len(s) > len("machine") && s[:len("machine")] == "machine" {
  24. s = s[len("machine"):]
  25. for k := 0; k < len(s); k++ {
  26. if s[k] == ' ' || s[k] == '\t' {
  27. s = s[1:]
  28. }
  29. break
  30. }
  31. if s == "amd64" {
  32. align = 8
  33. }
  34. break
  35. }
  36. }
  37. return align
  38. }