Skip to content
Snippets Groups Projects
Commit 8b30d41f authored by Christoph Petrausch's avatar Christoph Petrausch
Browse files

Assured that IPv4ToUint32 works also an interal 16 byte v4 representation

parent 64b98409
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,6 @@ import "net"
// IPv4ToUint32 converts an `net.IP` to an uint32 interpretation
func IPv4ToUint32(ip net.IP) uint32 {
ip = ip.To4()
return uint32(ip[3]) + uint32(ip[2])<<8 + uint32(ip[1])<<16 + uint32(ip[0])<<24
}
......@@ -3,6 +3,8 @@ package net
import (
"testing"
"net"
"github.com/stretchr/testify/assert"
)
......@@ -23,6 +25,10 @@ func TestIPv4ToUint32(t *testing.T) {
input: []byte{172, 24, 5, 1},
expected: 2887255297,
},
{
input: net.ParseIP("172.24.5.1"),
expected: 2887255297,
},
}
for _, test := range tests {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment