From cae888c6e145eaa3557c61c0392024b3f3b380e4 Mon Sep 17 00:00:00 2001 From: Kevin Wallace Date: Thu, 9 Jun 2016 22:56:00 -0700 Subject: give up trying to distinguish 1.2.3.4 from ::ffff:1.2.3.4 The Go net package goes to great lengths to treat them the same. This code didn't work. net.LookupAddr treats them both as v4 addresses. I give up. --- main.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/main.go b/main.go index 241a6b5..51fa6cb 100644 --- a/main.go +++ b/main.go @@ -77,7 +77,7 @@ func resolveArg(arg string) ([]net.IPNet, error) { } func resolveHost(host string, canLookup bool) ([]net.IP, error) { - ip := parseIP(host) + ip := net.ParseIP(host) if ip != nil { return []net.IP{ip}, nil } @@ -86,14 +86,3 @@ func resolveHost(host string, canLookup bool) ([]net.IP, error) { } return nil, fmt.Errorf("can't parse IP") } - -func parseIP(s string) net.IP { - ip := net.ParseIP(s) - // net.ParseIP provides no way to distinguish "::ffff:1.2.3.4" from "1.2.3.4"; - // this attempts to do so by assuming any IPv6 address contains a ':'. - // I think this is an accurate heuristic, but I am not sure of it. - if !strings.Contains(s, ":") { - ip = ip.To4() - } - return ip -} -- cgit v1.2.3