mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
24 lines
390 B
Go
24 lines
390 B
Go
package irc
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func AddrLookupHostname(addr net.Addr) string {
|
|
addrStr := addr.String()
|
|
ipaddr, _, err := net.SplitHostPort(addrStr)
|
|
if err != nil {
|
|
return addrStr
|
|
}
|
|
return LookupHostname(ipaddr)
|
|
}
|
|
|
|
func LookupHostname(addr string) string {
|
|
names, err := net.LookupAddr(addr)
|
|
if err != nil {
|
|
return addr
|
|
}
|
|
return strings.TrimSuffix(names[0], ".")
|
|
}
|