2012-04-07 20:44:59 +02:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2012-12-09 07:54:58 +01:00
|
|
|
"strings"
|
2012-04-07 20:44:59 +02:00
|
|
|
)
|
|
|
|
|
2014-02-11 04:39:53 +01:00
|
|
|
func AddrLookupHostname(addr net.Addr) string {
|
2012-12-09 07:54:58 +01:00
|
|
|
addrStr := addr.String()
|
|
|
|
ipaddr, _, err := net.SplitHostPort(addrStr)
|
|
|
|
if err != nil {
|
|
|
|
return addrStr
|
|
|
|
}
|
2014-02-11 04:39:53 +01:00
|
|
|
return LookupHostname(ipaddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func LookupHostname(addr string) string {
|
|
|
|
names, err := net.LookupAddr(addr)
|
2012-12-09 07:54:58 +01:00
|
|
|
if err != nil {
|
2014-02-11 04:39:53 +01:00
|
|
|
return addr
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
2014-02-11 04:39:53 +01:00
|
|
|
return strings.TrimSuffix(names[0], ".")
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|