summaryrefslogtreecommitdiff
path: root/common/spio.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/spio.c')
-rw-r--r--common/spio.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/common/spio.c b/common/spio.c
index 67e0405..a723936 100644
--- a/common/spio.c
+++ b/common/spio.c
@@ -113,6 +113,7 @@ void spio_init(spio_t* io, const char* name)
void spio_attach(spctx_t* ctx, spio_t* io, int fd, struct sockaddr_any* peer)
{
struct sockaddr_any peeraddr;
+ struct sockaddr_any locaddr;
io->fd = fd;
@@ -130,6 +131,17 @@ void spio_attach(spctx_t* ctx, spio_t* io, int fd, struct sockaddr_any* peer)
strlcpy(io->peername, "UNKNOWN", MAXPATHLEN);
}
+ /* Get the address on which we accepted the connection */
+ memset(&locaddr, 0, sizeof(locaddr));
+ SANY_LEN(locaddr) = sizeof(locaddr);
+
+ if(getsockname(fd, &SANY_ADDR(locaddr), &SANY_LEN(locaddr)) == -1 ||
+ sock_any_ntop(&locaddr, io->localname, MAXPATHLEN, SANY_OPT_NOPORT) == -1)
+ {
+ sp_message(ctx, LOG_WARNING, "%s: couldn't get socket address", GET_IO_NAME(io));
+ strlcpy(io->localname, "UNKNOWN", MAXPATHLEN);
+ }
+
/* As a double check */
io->line[0] = 0;
io->_nx = NULL;