3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

fix reverse dns

This commit is contained in:
Jeremy Latt 2014-02-10 19:39:53 -08:00
parent 4379cb8e1c
commit a34443f155
3 changed files with 12 additions and 19 deletions

View File

@ -33,7 +33,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
client := &Client{
channels: make(ChannelSet),
conn: conn,
hostname: LookupHostname(conn.RemoteAddr()),
hostname: AddrLookupHostname(conn.RemoteAddr()),
replies: replies,
server: server,
}

View File

@ -63,19 +63,19 @@ func StringWriteChan(conn net.Conn) chan<- string {
return ch
}
func LookupHostname(addr net.Addr) string {
func AddrLookupHostname(addr net.Addr) string {
addrStr := addr.String()
ipaddr, _, err := net.SplitHostPort(addrStr)
if err != nil {
return addrStr
}
switch ipaddr {
case "127.0.0.1", "::1":
return "localhost"
}
names, err := net.LookupAddr(ipaddr)
if err != nil {
return ipaddr
}
return names[0][0 : len(names[0])-1]
return LookupHostname(ipaddr)
}
func LookupHostname(addr string) string {
names, err := net.LookupAddr(addr)
if err != nil {
return addr
}
return strings.TrimSuffix(names[0], ".")
}

View File

@ -14,7 +14,6 @@ type Server struct {
channels ChannelNameMap
commands chan<- Command
ctime time.Time
hostname string
name string
operators map[string]string
password string
@ -94,7 +93,6 @@ func (s *Server) listen(config ListenerConfig) {
log.Fatal("Server.Listen: ", err)
}
s.hostname = LookupHostname(listener.Addr())
log.Print("Server.Listen: listening on ", config.Address)
for {
@ -404,10 +402,5 @@ func (msg *CapCommand) HandleServer(server *Server) {
}
func (msg *ProxyCommand) HandleServer(server *Server) {
client := msg.Client()
addr, err := net.ResolveIPAddr("ip", msg.sourceIP)
if err != nil {
return
}
client.hostname = LookupHostname(addr)
msg.Client().hostname = LookupHostname(msg.sourceIP)
}