You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
639 B

  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. "encoding/binary"
  7. "unsafe"
  8. )
  9. var (
  10. // NativeEndian is the machine native endian implementation of
  11. // ByteOrder.
  12. NativeEndian binary.ByteOrder
  13. kernelAlign int
  14. )
  15. func init() {
  16. i := uint32(1)
  17. b := (*[4]byte)(unsafe.Pointer(&i))
  18. if b[0] == 1 {
  19. NativeEndian = binary.LittleEndian
  20. } else {
  21. NativeEndian = binary.BigEndian
  22. }
  23. kernelAlign = probeProtocolStack()
  24. }
  25. func roundup(l int) int {
  26. return (l + kernelAlign - 1) & ^(kernelAlign - 1)
  27. }