Przeglądaj źródła

network order functionality changed based on endianess

salamaniibm 7 lat temu
rodzic
commit
dd396c9ea0
1 zmienionych plików z 6 dodań i 2 usunięć
  1. 6 2
      pkg/ip/ipnet.go

+ 6 - 2
pkg/ip/ipnet.go

@@ -60,8 +60,12 @@ func (ip IP4) ToIP() net.IP {
 }
 
 func (ip IP4) NetworkOrder() uint32 {
-	a, b, c, d := byte(ip>>24), byte(ip>>16), byte(ip>>8), byte(ip)
-	return uint32(a) | (uint32(b) << 8) | (uint32(c) << 16) | (uint32(d) << 24)
+	if NativelyLittle() {
+		a, b, c, d := byte(ip>>24), byte(ip>>16), byte(ip>>8), byte(ip)
+		return uint32(a) | (uint32(b) << 8) | (uint32(c) << 16) | (uint32(d) << 24)
+	} else {
+		return uint32(ip)
+	}
 }
 
 func (ip IP4) String() string {