net/dnsclient.go: Add LookupReverse(addr string) []string, os.Error
I have added a function to perform reverse lookups by retrieving the appropriate PTR records.
There is also an accompanying function/test to compute the in-addr.arpa. and ip6.arpa.
I also added a reverse static lookup for /etc/hosts.
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go File src/pkg/net/dnsclient.go (right): http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go#newcode369 src/pkg/net/dnsclient.go:369: type PTR struct { This isn't used anywhere as ...
14 years, 5 months ago
(2011-01-04 05:29:20 UTC)
#3
PTAL. Comments and questions inline. On 2011/01/04 05:29:20, adg wrote: > http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go > File src/pkg/net/dnsclient.go ...
14 years, 5 months ago
(2011-01-05 00:48:54 UTC)
#4
PTAL.
Comments and questions inline.
On 2011/01/04 05:29:20, adg wrote:
> http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go
> File src/pkg/net/dnsclient.go (right):
>
>
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go#new...
> src/pkg/net/dnsclient.go:369: type PTR struct {
> This isn't used anywhere as far as I can see.
>
>
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go#new...
Removed.
> src/pkg/net/dnsclient.go:376: if strings.Count(addr, ".") == 3 {
> First handle the error case, and return.
> Then handle this case, and return.
> Finally, handle the ipv6 case.
>
>
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go#new...
Rewritten.
> src/pkg/net/dnsclient.go:378: arpa = octets[3] + "." + octets[2] + "." +
> octets[1] + "." + octets[0] + ".in-addr.arpa."
> This doesn't validate the input at all. Is that desirable?
>
>
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/dnsclient.go#new...
> src/pkg/net/dnsclient.go:379: } else if strings.Count(addr, ":") >= 2 {
> This section on decoding the ipv6 address is much more complex than it need
be,
> largely because it tries to manipulate text instead of the actual semantic
data.
>
> First parse the IP address using the ParseIP function, then transform it to
the
> desired output format with something like:
>
> s := fmt.Sprintf("%x", ip)
> var buf bytes.Buffer
> for i := len(s)-1; i >= 0; i-- {
> if buf.Len() > 0 {
> buf.WriteByte('.')
> }
> buf.WriteByte(s[i])
> }
> return buf.String() + ".ip6.arpa."
>
> http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/hosts.go
> File src/pkg/net/hosts.go (right):
>
>
http://codereview.appspot.com/3851041/diff/20001/src/pkg/net/hosts.go#newcode50
Done.
> src/pkg/net/hosts.go:50: is[f[0]] = append(is[f[0]], h)
> Forward mapping is not the same as reverse mapping. This cache would prevent
> doing an RDNS lookup of an IP that is in the hosts file.
Is that not desireable? The primary reason I added this was because local IPs
in the hosts file won't resolve and (for whatever reason) ::1 doesn't resolve to
localhost when you look up the PTR record for 1.*.ip6.arpa. even though
1.0.0.127.in-addr.arpa. looks up to localhost. It is in my hosts file however,
so with this added I get the proper reverse lookup for ::1. My machine also has
fe80::1 mapped to localhost, which is in the hosts file, which probably wouldn't
rDNS properly either. Should I do the RDNS and only look in the hosts file if
the RDNS doesn't come back?
~Kyle
http://codereview.appspot.com/3851041/diff/26001/src/pkg/net/dnsclient.go File src/pkg/net/dnsclient.go (right): http://codereview.appspot.com/3851041/diff/26001/src/pkg/net/dnsclient.go#newcode369 src/pkg/net/dnsclient.go:369: // Get the in-addr.arpa. or ip6.arpa. for the address ...
14 years, 5 months ago
(2011-01-05 02:39:39 UTC)
#5
Issue 3851041: code review 3851041: net/dnsclient.go: Add LookupReverse(addr string) []str...
Created 14 years, 5 months ago by Kyle Lemons
Modified 14 years, 5 months ago
Reviewers:
Base URL:
Comments: 22