From 8b30d41ffc57fe535947f02f86e67ebf0b67368a Mon Sep 17 00:00:00 2001
From: Christoph Petrausch <christoph.petrausch@inovex.de>
Date: Wed, 23 May 2018 15:33:31 +0200
Subject: [PATCH] Assured that IPv4ToUint32 works also an interal 16 byte v4
 representation

---
 net/helper.go      | 1 +
 net/helper_test.go | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/net/helper.go b/net/helper.go
index 4f7319cd..4b82b242 100644
--- a/net/helper.go
+++ b/net/helper.go
@@ -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
 }
diff --git a/net/helper_test.go b/net/helper_test.go
index 7a267c3c..d5a038cb 100644
--- a/net/helper_test.go
+++ b/net/helper_test.go
@@ -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 {
-- 
GitLab