]> Cypherpunks.ru repositories - goircd.git/commitdiff
Perform DNS lookup of client addresses
authorBjörn Busse <mail@baerlin.eu>
Sun, 18 Oct 2015 20:07:57 +0000 (22:07 +0200)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 19 Oct 2015 08:22:11 +0000 (11:22 +0300)
README
client.go
room.go

diff --git a/README b/README
index b6291eae0e3a09cff6803d883ef94b632c23f0da..3793978dfa83805f8a13bbd5e04467b51d937be0 100644 (file)
--- 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:
 
index a43cc1efc1eb781a1de8b7f07667857402550480..fbaf8a326e8d6e3137f50e9ed2ee202013846497 100644 (file)
--- 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 2a5f22a2164d60826117cadd0b560017ae3694d4..276397fd44f6e823671f94824225289dfafc48ec 100644 (file)
--- 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",