diff options
author | Kevin Wallace <kevin@pentabarf.net> | 2016-06-09 22:56:00 -0700 |
---|---|---|
committer | Kevin Wallace <kevin@pentabarf.net> | 2016-06-09 22:56:00 -0700 |
commit | cae888c6e145eaa3557c61c0392024b3f3b380e4 (patch) | |
tree | c4879c853236279bc7d404818802f2a7d658d420 | |
parent | initial commit (diff) |
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.
-rw-r--r-- | main.go | 13 |
1 files changed, 1 insertions, 12 deletions
@@ -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 -} |