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
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
)
2014-02-11 04:39:53 +01:00
func AddrLookupHostname(addr net.Addr) string {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
return addrStr
}
2014-02-11 04:39:53 +01:00
return LookupHostname(ipaddr)
}
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-11 04:39:53 +01:00
return strings.TrimSuffix(names[0], ".")
}