3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 16:09:32 +01:00
ergo/irc/net.go

30 lines
477 B
Go
Raw Normal View History

2012-04-07 20:44:59 +02:00
package irc
import (
"net"
"strings"
2012-04-07 20:44:59 +02:00
)
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))
2014-02-11 04:39:53 +01:00
}
func LookupHostname(addr string) string {
names, err := net.LookupAddr(addr)
if err != nil {
2014-02-11 04:39:53 +01:00
return addr
}
2014-02-14 03:59:45 +01:00
hostname := strings.TrimSuffix(names[0], ".")
return hostname
}