3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 20:09:41 +01:00
ergo/irc/net.go
2014-02-14 19:30:58 -08:00

30 lines
477 B
Go

package irc
import (
"net"
"strings"
)
func IPString(addr net.Addr) string {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
return addrStr
}
return ipaddr
}
func AddrLookupHostname(addr net.Addr) string {
return LookupHostname(IPString(addr))
}
func LookupHostname(addr string) string {
names, err := net.LookupAddr(addr)
if err != nil {
return addr
}
hostname := strings.TrimSuffix(names[0], ".")
return hostname
}