1
0
Fork 0
forked from External/ergo

fix reverse dns

This commit is contained in:
Jeremy Latt 2014-02-10 19:39:53 -08:00
parent 4379cb8e1c
commit a34443f155
3 changed files with 12 additions and 19 deletions

View file

@ -63,19 +63,19 @@ func StringWriteChan(conn net.Conn) chan<- string {
return ch
}
func LookupHostname(addr net.Addr) string {
func AddrLookupHostname(addr net.Addr) string {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
return addrStr
}
switch ipaddr {
case "127.0.0.1", "::1":
return "localhost"
}
names, err := net.LookupAddr(ipaddr)
if err != nil {
return ipaddr
}
return names[0][0 : len(names[0])-1]
return LookupHostname(ipaddr)
}
func LookupHostname(addr string) string {
names, err := net.LookupAddr(addr)
if err != nil {
return addr
}
return strings.TrimSuffix(names[0], ".")
}