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() +}