summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Busse <mail@baerlin.eu>2015-10-18 22:07:57 +0200
committerSergey Matveev <stargrave@stargrave.org>2015-10-19 11:22:11 +0300
commit66eaa48372228e098b464e8eac64d15a8582e9ef (patch)
tree0bf835edb06313d92ff7f4ee4ea94022ddf8d9f3
parent158ab243b29e99bfbe7a78ee48662fb132b47704 (diff)
downloadgoircd-66eaa48372228e098b464e8eac64d15a8582e9ef.tar.xz
Perform DNS lookup of client addresses
-rw-r--r--README2
-rw-r--r--client.go13
-rw-r--r--room.go2
3 files changed, 14 insertions, 3 deletions
diff --git a/README b/README
index b6291ea..3793978 100644
--- a/README
+++ b/README
@@ -11,7 +11,7 @@ It does not aim to replace full featured mass scalable IRC networks:
* It can not connect to other servers. Just standalone installation
* It has few basic IRC commands
* There is no support for channel operators, modes, votes, invites
-* No ident lookups, reverse DNS queries
+* No ident lookups
But it has some convincing features:
diff --git a/client.go b/client.go
index a43cc1e..fbaf8a3 100644
--- a/client.go
+++ b/client.go
@@ -51,8 +51,19 @@ type Client struct {
sync.Mutex
}
+func (c Client) Host() string {
+ addr := c.conn.RemoteAddr().String()
+ if host, _, err := net.SplitHostPort(addr); err == nil {
+ addr = host
+ }
+ if domains, err := net.LookupAddr(addr); err == nil {
+ addr = strings.TrimSuffix(domains[0], ".")
+ }
+ return addr
+}
+
func (c Client) String() string {
- return *c.nickname + "!" + *c.username + "@" + c.conn.RemoteAddr().String()
+ return *c.nickname + "!" + *c.username + "@" + c.Host()
}
func NewClient(conn net.Conn) *Client {
diff --git a/room.go b/room.go
index 2a5f22a..276397f 100644
--- a/room.go
+++ b/room.go
@@ -142,7 +142,7 @@ func (room *Room) Processor(events <-chan ClientEvent) {
"352",
*room.name,
*m.username,
- m.conn.RemoteAddr().String(),
+ m.Host(),
*hostname,
*m.nickname,
"H",