From 564a41d598a74684da5da2f84e5d9c757532c8a9 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 14 May 2019 15:29:52 +0300 Subject: [PATCH] + helpers: parseIPv4() --- helpers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/helpers.go b/helpers.go index 6f35caba..4d4d0b3f 100644 --- a/helpers.go +++ b/helpers.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "context" "errors" "fmt" @@ -387,3 +388,18 @@ func _Func() string { f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } + +// Parse input string and return IPv4 address +func parseIPv4(s string) net.IP { + ip := net.ParseIP(s) + if ip == nil { + return nil + } + + v4InV6Prefix := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff} + if !bytes.Equal(ip[0:12], v4InV6Prefix) { + return nil + } + + return ip.To4() +}