David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 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 | |
| 5 | package socket |
| 6 | |
| 7 | import ( |
| 8 | "encoding/binary" |
| 9 | "unsafe" |
| 10 | ) |
| 11 | |
| 12 | var ( |
| 13 | // NativeEndian is the machine native endian implementation of |
| 14 | // ByteOrder. |
| 15 | NativeEndian binary.ByteOrder |
| 16 | |
| 17 | kernelAlign int |
| 18 | ) |
| 19 | |
| 20 | func init() { |
| 21 | i := uint32(1) |
| 22 | b := (*[4]byte)(unsafe.Pointer(&i)) |
| 23 | if b[0] == 1 { |
| 24 | NativeEndian = binary.LittleEndian |
| 25 | } else { |
| 26 | NativeEndian = binary.BigEndian |
| 27 | } |
| 28 | kernelAlign = probeProtocolStack() |
| 29 | } |
| 30 | |
| 31 | func roundup(l int) int { |
| 32 | return (l + kernelAlign - 1) & ^(kernelAlign - 1) |
| 33 | } |