github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/route/sys.go (about) 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 5 // +build darwin dragonfly freebsd netbsd openbsd 6 7 package route 8 9 import "unsafe" 10 11 var ( 12 nativeEndian binaryByteOrder 13 kernelAlign int 14 wireFormats map[int]*wireFormat 15 ) 16 17 func init() { 18 i := uint32(1) 19 b := (*[4]byte)(unsafe.Pointer(&i)) 20 if b[0] == 1 { 21 nativeEndian = littleEndian 22 } else { 23 nativeEndian = bigEndian 24 } 25 kernelAlign, wireFormats = probeRoutingStack() 26 } 27 28 func roundup(l int) int { 29 if l == 0 { 30 return kernelAlign 31 } 32 return (l + kernelAlign - 1) &^ (kernelAlign - 1) 33 } 34 35 type wireFormat struct { 36 extOff int // offset of header extension 37 bodyOff int // offset of message body 38 parse func(RIBType, []byte) (Message, error) 39 }