diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/spio.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/common/spio.c b/common/spio.c index a723936..c26f81a 100644 --- a/common/spio.c +++ b/common/spio.c @@ -117,6 +117,18 @@ void spio_attach(spctx_t* ctx, spio_t* io, int fd, struct sockaddr_any* peer) io->fd = fd; + /* 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) + { + if (errno != EAFNOSUPPORT) + sp_message(ctx, LOG_WARNING, "%s: couldn't get socket address", GET_IO_NAME(io)); + strlcpy(io->localname, "UNKNOWN", MAXPATHLEN); + } + /* If the caller doesn't want the peer then use our own */ if (peer == NULL) peer = &peeraddr; @@ -127,21 +139,11 @@ void spio_attach(spctx_t* ctx, spio_t* io, int fd, struct sockaddr_any* peer) if(getpeername(fd, &SANY_ADDR(*peer), &SANY_LEN(*peer)) == -1 || sock_any_ntop(peer, io->peername, MAXPATHLEN, SANY_OPT_NOPORT) == -1) { - sp_message(ctx, LOG_WARNING, "%s: couldn't get peer address", GET_IO_NAME(io)); + if (errno != EAFNOSUPPORT) + sp_message(ctx, LOG_WARNING, "%s: couldn't get peer address", GET_IO_NAME(io)); 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; |