3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00
ergo/irc/net.go
2014-03-12 16:45:22 -07:00

30 lines
502 B
Go

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