mirror of
https://github.com/nmap/nmap.git
synced 2025-12-13 03:09:02 +00:00
Refactor get_hostaddr_string to get_peeraddr_string.
All the information passed as arguments is present in an iod, and we only call this with members of one iod. Change it to accept just an iod as an argument.
This commit is contained in:
@@ -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 "<address>:<port>". */
|
||||
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
|
||||
#endif
|
||||
sprintf(buffer, "%s:%hu", inet_ntop_ez(addr, len), port);
|
||||
|
||||
if (iod->peer.ss_family == AF_UNIX) {
|
||||
sprintf(buffer, "%s", get_unixsock_path(&iod->peer));
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
sprintf(buffer, "%s:%d", inet_ntop_ez(&iod->peer, iod->peerlen), nsi_peerport((msiod *) iod));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
#include <netinet/in.h>
|
||||
#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 <sys/un.h>
|
||||
#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 "<address>:<port>". */
|
||||
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
|
||||
* "<address>:<port>". */
|
||||
char *get_peeraddr_string(const msiod *iod);
|
||||
|
||||
#endif /* NETUTILS_H */
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
|
||||
#include "nsock.h"
|
||||
#include "nsock_internal.h"
|
||||
#include "netutils.h"
|
||||
|
||||
#include <nbase.h>
|
||||
#include <stdarg.h>
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user