3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-23 04:19:25 +01:00
ergo/irc/net.go

30 lines
502 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-03-09 21:45:36 +01:00
func IPString(addr net.Addr) Name {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
2014-03-09 21:45:36 +01:00
return Name(addrStr)
}
2014-03-09 21:45:36 +01:00
return Name(ipaddr)
}
2014-03-09 21:45:36 +01:00
func AddrLookupHostname(addr net.Addr) Name {
return LookupHostname(IPString(addr))
2014-02-11 04:39:53 +01:00
}
2014-03-09 21:45:36 +01:00
func LookupHostname(addr Name) Name {
names, err := net.LookupAddr(addr.String())
if err != nil {
2014-03-09 21:45:36 +01:00
return Name(addr)
}
2014-02-14 03:59:45 +01:00
hostname := strings.TrimSuffix(names[0], ".")
2014-03-09 21:45:36 +01:00
return Name(hostname)
}