From fb6469c8959825d9269f2550d35406a5b5986552 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 14 Oct 2015 14:35:52 +0100 Subject: [PATCH] Print unix socket address when accepting connections --- src/libutil/addr.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 3ddd10289..5958e9e3e 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -228,8 +228,18 @@ rspamd_accept_from_socket (gint sock, rspamd_inet_addr_t **target) addr->slen = len; if (addr->af == AF_UNIX) { - addr->u.un = g_slice_alloc (sizeof (*addr->u.un)); - memcpy (&addr->u.un->addr, &su.su, sizeof (struct sockaddr_un)); + addr->u.un = g_slice_alloc0 (sizeof (*addr->u.un)); + /* Get name from the listening socket */ + len = sizeof (su); + + if (getsockname (sock, &su.sa, &len) != -1) { + memcpy (&addr->u.un->addr, &su.su, MIN (len, + sizeof (struct sockaddr_un))); + } + else { + /* Just copy socket address */ + memcpy (&addr->u.un->addr, &su.sa, sizeof (struct sockaddr)); + } } else { memcpy (&addr->u.in.addr, &su, MIN (len, sizeof (addr->u.in.addr))); -- 2.39.5