sys.go 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2016 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 darwin dragonfly freebsd netbsd openbsd
  5. package route
  6. import "unsafe"
  7. var (
  8. nativeEndian binaryByteOrder
  9. kernelAlign int
  10. rtmVersion byte
  11. wireFormats map[int]*wireFormat
  12. )
  13. func init() {
  14. i := uint32(1)
  15. b := (*[4]byte)(unsafe.Pointer(&i))
  16. if b[0] == 1 {
  17. nativeEndian = littleEndian
  18. } else {
  19. nativeEndian = bigEndian
  20. }
  21. // might get overridden in probeRoutingStack
  22. rtmVersion = sysRTM_VERSION
  23. kernelAlign, wireFormats = probeRoutingStack()
  24. }
  25. func roundup(l int) int {
  26. if l == 0 {
  27. return kernelAlign
  28. }
  29. return (l + kernelAlign - 1) &^ (kernelAlign - 1)
  30. }
  31. type wireFormat struct {
  32. extOff int // offset of header extension
  33. bodyOff int // offset of message body
  34. parse func(RIBType, []byte) (Message, error)
  35. }