aboutsummaryrefslogtreecommitdiffstats
path: root/irc.c
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2017-04-07 10:24:13 +0200
committerMarius Halden <marius.h@lden.org>2017-04-07 10:24:13 +0200
commitdd46ae5bef1c34773a3e7d3e2ef48fc013cef283 (patch)
treedecbedfb7b847c01493dc95890f2169b4b0e31f3 /irc.c
parentfebcb6dca01bb17e0197770a0e6596aaa98bcdbd (diff)
parent051506399e1455d88f6179010129308c754be936 (diff)
Merge branch 'master' into patched-master
Diffstat (limited to 'irc.c')
-rw-r--r--irc.c85
1 files changed, 49 insertions, 36 deletions
diff --git a/irc.c b/irc.c
index 7ba9ef8b..a1aae4ef 100644
--- a/irc.c
+++ b/irc.c
@@ -24,6 +24,7 @@
*/
#include "bitlbee.h"
+#include "canohost.h"
#include "ipc.h"
#include "dcc.h"
#include "lib/ssl_client.h"
@@ -41,9 +42,6 @@ static char *set_eval_certfp(set_t *set, char *value);
irc_t *irc_new(int fd)
{
irc_t *irc;
- struct sockaddr_storage sock;
- socklen_t socklen = sizeof(sock);
- char *host = NULL, *myhost = NULL;
irc_user_t *iu;
GSList *l;
set_t *s;
@@ -67,33 +65,6 @@ irc_t *irc_new(int fd)
irc->save_source_id = -1;
- if (global.conf->hostname) {
- myhost = g_strdup(global.conf->hostname);
- } else if (getsockname(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {
- char buf[NI_MAXHOST + 1];
-
- if (getnameinfo((struct sockaddr *) &sock, socklen, buf,
- NI_MAXHOST, NULL, 0, 0) == 0) {
- myhost = g_strdup(ipv6_unwrap(buf));
- }
- }
-
- if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {
- char buf[NI_MAXHOST + 1];
-
- if (getnameinfo((struct sockaddr *) &sock, socklen, buf,
- NI_MAXHOST, NULL, 0, 0) == 0) {
- host = g_strdup(ipv6_unwrap(buf));
- }
- }
-
- if (host == NULL) {
- host = g_strdup("localhost.localdomain");
- }
- if (myhost == NULL) {
- myhost = g_strdup("localhost.localdomain");
- }
-
if (global.conf->ping_interval > 0 && global.conf->ping_timeout > 0) {
irc->ping_source_id = b_timeout_add(global.conf->ping_interval * 1000, irc_userping, irc);
}
@@ -150,17 +121,16 @@ irc_t *irc_new(int fd)
#endif
irc->root = iu = irc_user_new(irc, ROOT_NICK);
- iu->host = g_strdup(myhost);
iu->fullname = g_strdup(ROOT_FN);
iu->f = &irc_user_root_funcs;
iu = irc_user_new(irc, NS_NICK);
- iu->host = g_strdup(myhost);
iu->fullname = g_strdup(ROOT_FN);
iu->f = &irc_user_root_funcs;
irc->user = g_new0(irc_user_t, 1);
- irc->user->host = g_strdup(host);
+
+ irc_set_hosts(irc, NULL, 0);
conf_loaddefaults(irc);
@@ -176,9 +146,6 @@ irc_t *irc_new(int fd)
"See doc/README for more information.");
}
- g_free(myhost);
- g_free(host);
-
/* libpurple doesn't like fork()s after initializing itself, so this
is the right moment to initialize it. */
#ifdef WITH_PURPLE
@@ -200,6 +167,52 @@ irc_t *irc_new(int fd)
return irc;
}
+void irc_set_hosts(irc_t *irc, const struct sockaddr *remote_addr, const socklen_t remote_addrlen)
+{
+ struct sockaddr_storage sock;
+ socklen_t socklen = sizeof(sock);
+ char *host = NULL, *myhost = NULL;
+ struct irc_user *iu;
+
+ if (global.conf->hostname) {
+ myhost = g_strdup(global.conf->hostname);
+ } else if (getsockname(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {
+ myhost = reverse_lookup((struct sockaddr*) &sock, socklen);
+ }
+
+ if (remote_addrlen > 0) {
+ host = reverse_lookup(remote_addr, remote_addrlen);
+ } else if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {
+ host = reverse_lookup((struct sockaddr*) &sock, socklen);
+ }
+
+ if (myhost == NULL) {
+ myhost = g_strdup("localhost.localdomain");
+ }
+ if (host == NULL) {
+ host = g_strdup("localhost.localdomain");
+ }
+
+ if (irc->root->host != irc->root->nick) {
+ g_free(irc->root->host);
+ }
+ irc->root->host = g_strdup(myhost);
+ if ((iu = irc_user_by_name(irc, NS_NICK))) {
+ if (iu->host != iu->nick) {
+ g_free(iu->host);
+ }
+ iu->host = g_strdup(myhost);
+ }
+
+ if (irc->user->host != irc->user->nick) {
+ g_free(irc->user->host);
+ }
+ irc->user->host = g_strdup(host);
+
+ g_free(myhost);
+ g_free(host);
+}
+
/* immed=1 makes this function pretty much equal to irc_free(), except that
this one will "log". In case the connection is already broken and we
shouldn't try to write to it. */