diff --git a/net/ip.go b/net/ip.go index 46b7350dd8a10fe3fa2359073f2a6ce69874ea6b..a277a19235f6bed166e6d6312961e38a952cb33b 100644 --- a/net/ip.go +++ b/net/ip.go @@ -41,11 +41,6 @@ func IPv6FromBlocks(b1, b2, b3, b4, b5, b6, b7, b8 uint16) IP { uint64(uint64(b5)<<48+uint64(b6)<<32+uint64(b7)<<16+uint64(b8))) } -// ToUint32 returns the uint32 representation of an IP address -func (ip *IP) ToUint32() uint32 { - return uint32(^uint64(0) >> 32 & ip.lower) -} - // Equal returns true if ip is equal to other func (ip IP) Equal(other IP) bool { return ip == other @@ -110,7 +105,7 @@ func (ip IP) Bytes() []byte { } func (ip IP) bytesIPv4() []byte { - u := ip.ToUint32() + u := uint32(^uint64(0) >> 32 & ip.lower) return []byte{ byte(u & 0xFF000000 >> 24), byte(u & 0x00FF0000 >> 16), diff --git a/net/ip_test.go b/net/ip_test.go index a10019322f390dab4890ffe2c3f4eafbd0ade8fb..7283cfa83188ae4504c135cbfe00ec0a730ef25d 100644 --- a/net/ip_test.go +++ b/net/ip_test.go @@ -8,34 +8,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestToUint32(t *testing.T) { - tests := []struct { - name string - val uint64 - expected uint32 - }{ - { - name: "IP: 172.24.5.1", - val: 2887255297, - expected: 2887255297, - }, - { - name: "bigger than IPv4 address", - val: 2887255295 + 17179869184, - expected: 2887255295, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ip := IP{ - lower: test.val, - } - assert.Equal(t, test.expected, ip.ToUint32()) - }) - } -} - func TestCompare(t *testing.T) { tests := []struct { name string