+ helpers: parseIPv4()

This commit is contained in:
Simon Zolin 2019-05-14 15:29:52 +03:00
parent c3204664c3
commit 564a41d598

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@ -387,3 +388,18 @@ func _Func() string {
f := runtime.FuncForPC(pc[0]) f := runtime.FuncForPC(pc[0])
return path.Base(f.Name()) 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()
}