Skip to content
Snippets Groups Projects
Commit 6b9cdaff authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

removed ToUint32

parent f88c87e5
No related branches found
No related tags found
No related merge requests found
......@@ -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),
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment