fix(net,linux): move IsLittleEndian to internal
This commit is contained in:
parent
e4e6ed2efa
commit
f11e3ba120
|
@ -0,0 +1,10 @@
|
|||
package common
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// IsLittleEndian checks if the current platform uses little-endian.
|
||||
// copied from https://github.com/ntrrg/ntgo/blob/v0.8.0/runtime/infrastructure.go#L16 (MIT License)
|
||||
func IsLittleEndian() bool {
|
||||
var x int16 = 0x0011
|
||||
return *(*byte)(unsafe.Pointer(&x)) == 0x11
|
||||
}
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"unsafe"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/internal/common"
|
||||
)
|
||||
|
@ -272,10 +271,3 @@ func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) {
|
|||
|
||||
return []IOCountersStat{r}, nil
|
||||
}
|
||||
|
||||
// IsLittleEndian checks if the current platform uses little-endian.
|
||||
// copied from https://github.com/ntrrg/ntgo/blob/v0.8.0/runtime/infrastructure.go#L16 (MIT License)
|
||||
func IsLittleEndian() bool {
|
||||
var x int16 = 0x0011
|
||||
return *(*byte)(unsafe.Pointer(&x)) == 0x11
|
||||
}
|
||||
|
|
|
@ -723,7 +723,7 @@ func decodeAddressWithContext(ctx context.Context, family uint32, src string) (A
|
|||
var ip net.IP
|
||||
|
||||
if family == syscall.AF_INET {
|
||||
if IsLittleEndian() {
|
||||
if common.IsLittleEndian() {
|
||||
ip = net.IP(ReverseWithContext(ctx, decoded))
|
||||
} else {
|
||||
ip = net.IP(decoded)
|
||||
|
|
|
@ -151,7 +151,7 @@ func TestDecodeAddress(t *testing.T) {
|
|||
Error: true,
|
||||
},
|
||||
}
|
||||
if IsLittleEndian() {
|
||||
if common.IsLittleEndian() {
|
||||
addr["0500000A:0016"] = AddrTest{
|
||||
IP: "10.0.0.5",
|
||||
Port: 22,
|
||||
|
|
Loading…
Reference in New Issue