3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00
ergo/irc/net.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], ".")
}