transparent-proxy/server/hack.go

27 lines
490 B
Go
Raw Permalink Normal View History

2017-08-07 15:57:17 +08:00
package server
import (
"unsafe"
)
func isLittleEndian() bool {
var placeHolder uint32 = 0x0000FFFF
return (*[4]byte)(unsafe.Pointer(&placeHolder))[0] == 0xFF
}
func be32toh(host uint32) uint32 {
if isLittleEndian() {
return ((host & 255) << 24) | (((host >> 8) & 255) << 16) | (((host >> 16) & 255) << 8) | (host >> 24)
} else {
return host
}
}
func be16toh(host uint16) uint16 {
if isLittleEndian() {
return ((host & 255) << 8) | (host >> 8)
} else {
return host
}
}