From 26cdb4cf36d93912b4a005239b855d121204aef2 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 25 Aug 2021 22:31:38 -0400 Subject: [PATCH] fix #1650 RPL_WHOISACTUALLY should display some arbitrarily chosen IP address and hostname. --- irc/client.go | 6 +----- irc/getters.go | 11 +++++++++++ irc/server.go | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/irc/client.go b/irc/client.go index 9376927e..fc9f8015 100644 --- a/irc/client.go +++ b/irc/client.go @@ -613,11 +613,7 @@ func (client *Client) getIPNoMutex() net.IP { // IPString returns the IP address of this client as a string. func (client *Client) IPString() string { - ip := client.IP().String() - if 0 < len(ip) && ip[0] == ':' { - ip = "0" + ip - } - return ip + return utils.IPStringToHostname(client.IP().String()) } // t returns the translated version of the given string, based on the languages configured by the client. diff --git a/irc/getters.go b/irc/getters.go index c2fd54d2..0e49c9fc 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -145,6 +145,17 @@ func (client *Client) removeSession(session *Session) (success bool, length int) return } +// #1650: show an arbitrarily chosen session IP and hostname in RPL_WHOISACTUALLY +func (client *Client) getWhoisActually() (ip net.IP, hostname string) { + client.stateMutex.RLock() + defer client.stateMutex.RUnlock() + + for _, session := range client.sessions { + return session.IP(), session.rawHostname + } + return utils.IPv4LoopbackAddress, client.server.name +} + func (client *Client) Nick() string { client.stateMutex.RLock() defer client.stateMutex.RUnlock() diff --git a/irc/server.go b/irc/server.go index 3e041c7b..6766302f 100644 --- a/irc/server.go +++ b/irc/server.go @@ -482,7 +482,8 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff } } if client == target || oper.HasRoleCapab("ban") { - rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, target.RawHostname()), target.IPString(), client.t("Actual user@host, Actual IP")) + ip, hostname := target.getWhoisActually() + rb.Add(nil, client.server.name, RPL_WHOISACTUALLY, cnick, tnick, fmt.Sprintf("%s@%s", targetInfo.username, hostname), utils.IPStringToHostname(ip.String()), client.t("Actual user@host, Actual IP")) } if client == target || oper.HasRoleCapab("samode") { rb.Add(nil, client.server.name, RPL_WHOISMODES, cnick, tnick, fmt.Sprintf(client.t("is using modes +%s"), target.modes.String()))