mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix reverse dns
This commit is contained in:
parent
4379cb8e1c
commit
a34443f155
@ -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,
|
||||
}
|
||||
|
20
irc/net.go
20
irc/net.go
@ -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], ".")
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user