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{ client := &Client{
channels: make(ChannelSet), channels: make(ChannelSet),
conn: conn, conn: conn,
hostname: LookupHostname(conn.RemoteAddr()), hostname: AddrLookupHostname(conn.RemoteAddr()),
replies: replies, replies: replies,
server: server, server: server,
} }

View File

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

View File

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