diff --git a/nsock/src/netutils.c b/nsock/src/netutils.c index d94f06464..58d6d2ff0 100644 --- a/nsock/src/netutils.c +++ b/nsock/src/netutils.c @@ -137,9 +137,15 @@ int maximize_fdlimit(void) { return 0; } +#if HAVE_SYS_UN_H + #define PEER_STR_LEN sizeof(((struct sockaddr_un *) 0)->sun_path) +#else + #define PEER_STR_LEN sizeof("[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]:xxxxx") +#endif + #if HAVE_SYS_UN_H /* Get the UNIX domain socket path or empty string if the address family != AF_UNIX. */ -const char *get_unixsock_path(struct sockaddr_storage *addr) +const char *get_unixsock_path(const struct sockaddr_storage *addr) { if (!addr || addr->ss_family != AF_UNIX) return ""; @@ -153,19 +159,17 @@ const char *get_unixsock_path(struct sockaddr_storage *addr) * In case we have support for UNIX domain sockets, function returns * string containing path to UNIX socket if the address family is AF_UNIX, * otherwise it returns string containing "
:". */ -char *get_hostaddr_string(struct sockaddr_storage *addr, size_t len, unsigned short port) +char *get_peeraddr_string(const msiod *iod) { static char buffer[PEER_STR_LEN]; - if (!addr) - return ""; - #if HAVE_SYS_UN_H - if (addr->ss_family == AF_UNIX) - sprintf(buffer, "%s", get_unixsock_path(addr)); - else + if (iod->peer.ss_family == AF_UNIX) { + sprintf(buffer, "%s", get_unixsock_path(&iod->peer)); + return buffer; + } #endif - sprintf(buffer, "%s:%hu", inet_ntop_ez(addr, len), port); + sprintf(buffer, "%s:%d", inet_ntop_ez(&iod->peer, iod->peerlen), nsi_peerport((msiod *) iod)); return buffer; } diff --git a/nsock/src/netutils.h b/nsock/src/netutils.h index f03125a8e..915f57202 100644 --- a/nsock/src/netutils.h +++ b/nsock/src/netutils.h @@ -67,6 +67,8 @@ #include #endif +#include "nsock_internal.h" + #ifdef WIN32 #include "nbase_winconfig.h" /* nbase_winunix.h somehow reason.h to get included */ @@ -77,28 +79,19 @@ #include #endif -#if HAVE_SYS_UN_H - #define PEER_STR_LEN sizeof(((struct sockaddr_un *) 0)->sun_path) -#else - #define PEER_STR_LEN sizeof("[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]:xxxxx") -#endif - /* Maximize the number of file descriptors (including sockets) allowed for this * process and return that maximum value (note -- you better not actually open * this many -- stdin, stdout, other files opened by libraries you use, etc. all * count toward this limit. Leave a little slack */ int maximize_fdlimit(void); -#if HAVE_SYS_UN_H -/* Get the UNIX domain socket path or NULL if the socket family != AF_UNIX. */ -const char *get_unixsock_path(struct sockaddr_storage *addr); -#endif +/* Get the UNIX domain socket path or empty string if the address family != AF_UNIX. */ +const char *get_unixsock_path(const struct sockaddr_storage *addr); -/* Get the peer/host address string. - * In case we have support for UNIX domain sockets, function returns - * string containing path to UNIX socket if the address family is AF_UNIX, - * otherwise it returns string containing "
:". */ -char *get_hostaddr_string(struct sockaddr_storage *addr, size_t len, unsigned short port); +/* Get the peer address string. In case of a Unix domain socket, returns the + * path to UNIX socket, otherwise it returns string containing + * "
:". */ +char *get_peeraddr_string(const msiod *iod); #endif /* NETUTILS_H */ diff --git a/nsock/src/nsock_core.c b/nsock/src/nsock_core.c index 176864972..ff40d1bf4 100644 --- a/nsock/src/nsock_core.c +++ b/nsock/src/nsock_core.c @@ -1274,8 +1274,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) { case NSE_TYPE_CONNECT_SSL: nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]", nse_type2str(nse->type), nse_status2str(nse->status), - errstr, nse->id, get_hostaddr_string(&nsi->peer, - nsi->peerlen, (unsigned short)nsi_peerport(nsi))); + errstr, nse->id, get_peeraddr_string(nsi)); break; case NSE_TYPE_READ: @@ -1283,8 +1282,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) { if (nsi->peerlen > 0) { nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]", nse_type2str(nse->type), nse_status2str(nse->status), - errstr, nse->id, get_hostaddr_string(&nsi->peer, - nsi->peerlen, (unsigned short)nsi_peerport(nsi))); + errstr, nse->id, get_peeraddr_string(nsi)); } else { nsock_trace(ms, "Callback: %s %s %sfor EID %li (peer unspecified)", nse_type2str(nse->type), nse_status2str(nse->status), @@ -1304,8 +1302,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) { if (nsi->peerlen > 0) { nsock_trace(ms, "Callback: %s %s for EID %li [%s] %s(%d bytes)%s", nse_type2str(nse->type), nse_status2str(nse->status), - nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, - (unsigned short)nsi_peerport(nsi)), + nse->id, get_peeraddr_string(nsi), nse_eof(nse)? "[EOF]" : "", strlength, displaystr); } else { nsock_trace(ms, "Callback %s %s for EID %li (peer unspecified) %s(%d bytes)%s", @@ -1318,8 +1315,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) { case NSE_TYPE_WRITE: nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]", nse_type2str(nse->type), nse_status2str(nse->status), errstr, - nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, - (unsigned short)nsi_peerport(nsi))); + nse->id, get_peeraddr_string(nsi)); break; case NSE_TYPE_TIMER: diff --git a/nsock/src/nsock_read.c b/nsock/src/nsock_read.c index 3e1b441e6..87fb587c7 100644 --- a/nsock/src/nsock_read.c +++ b/nsock/src/nsock_read.c @@ -56,6 +56,7 @@ /* $Id$ */ #include "nsock_internal.h" +#include "netutils.h" /* Read up to nlines lines (terminated with \n, which of course includes \r\n), @@ -75,7 +76,7 @@ nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle if (ms->tracelevel > 0) { if (nsi->peerlen > 0) nsock_trace(ms, "Read request for %d lines from IOD #%li [%s] EID %li", - nlines, nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)), + nlines, nsi->id, get_peeraddr_string(nsi), nse->id); else nsock_trace(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li", @@ -104,7 +105,7 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle if (ms->tracelevel > 0) { if (nsi->peerlen > 0) nsock_trace(ms, "Read request for %d bytes from IOD #%li [%s] EID %li", - nbytes, nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)), + nbytes, nsi->id, get_peeraddr_string(nsi), nse->id); else nsock_trace(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li", @@ -133,7 +134,7 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler han if (ms->tracelevel > 0) { if (nsi->peerlen > 0) nsock_trace(ms, "Read request from IOD #%li [%s] (timeout: %dms) EID %li", - nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)), + nsi->id, get_peeraddr_string(nsi), timeout_msecs, nse->id); else nsock_trace(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li", diff --git a/nsock/src/nsock_write.c b/nsock/src/nsock_write.c index 5995b24a8..50ffbbbab 100644 --- a/nsock/src/nsock_write.c +++ b/nsock/src/nsock_write.c @@ -57,6 +57,7 @@ #include "nsock.h" #include "nsock_internal.h" +#include "netutils.h" #include #include @@ -113,7 +114,7 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl } nsock_trace(nsp, "Sendto request for %d bytes to IOD #%li EID %li [%s]%s", datalen, nsi->id, nse->id, - get_hostaddr_string(&nse->writeinfo.dest, nse->writeinfo.destlen, port), + get_peeraddr_string(nse->iod), displaystr); } @@ -152,7 +153,7 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod, } else displaystr[0] = '\0'; if (nsi->peerlen > 0) nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s", datalen, nsi->id, - nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)), + nse->id, get_peeraddr_string(nsi), displaystr); else nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", datalen, @@ -226,7 +227,7 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod, } if (nsi->peerlen > 0) nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s", strlength, nsi->id, - nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)), + nse->id, get_peeraddr_string(nsi), displaystr); else nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", strlength,