From 053b0fdd056d63c763744663b57fdb864d89e1a5 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Tue, 14 Mar 2017 16:54:21 +0100 Subject: [PATCH] Get hostname --- source/ircd/connection.d | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/ircd/connection.d b/source/ircd/connection.d index b0c85bb..63068d0 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -5,6 +5,7 @@ import std.string; import std.algorithm; import std.range; import std.conv; +import std.socket; import vibe.core.core; import vibe.stream.operations; @@ -126,6 +127,7 @@ class Connection writeln("mode: " ~ message.parameters[1]); writeln("unused: " ~ message.parameters[2]); realname = message.parameters[3]; + hostname = getHost(); send(Message(_server.name, "001", [nick, "Welcome to the Internet Relay Network " ~ mask], true)); send(Message(_server.name, "002", [nick, "Your host is " ~ _server.name ~ ", running version " ~ _server.versionString], true)); @@ -177,5 +179,16 @@ class Connection } } } + + string getHost() + { + auto address = parseAddress(_connection.peerAddress); + auto hostname = address.toHostNameString; + if(hostname is null) + { + hostname = address.toAddrString; + } + return hostname; + } }