1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-10 17:59:04 +00:00

Code cleanup.

Made get_peeraddr_string() return "peer unspecified" if peerlen <= 0.
This saves a handful duplicate lines that did the check externally.
This commit is contained in:
henri
2013-06-15 12:33:27 +00:00
parent 6238087e9b
commit a493296c54
4 changed files with 18 additions and 34 deletions

View File

@@ -186,7 +186,10 @@ static char *get_addr_string(const struct sockaddr_storage *ss, size_t sslen) {
* string containing path to UNIX socket if the address family is AF_UNIX,
* otherwise it returns string containing "<address>:<port>". */
char *get_peeraddr_string(const msiod *iod) {
if (iod->peerlen > 0)
return get_addr_string(&iod->peer, iod->peerlen);
else
return "peer unspecified";
}
/* Get the local bind address string. */

View File

@@ -1265,8 +1265,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
if (nse->status != NSE_STATUS_SUCCESS) {
nsock_log_info(ms, "Callback: %s %s %sfor EID %li [%s]",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id,
(nsi->peerlen > 0) ? get_peeraddr_string(nsi) : "peer unspecified");
errstr, nse->id, get_peeraddr_string(nsi));
} else {
str = nse_readbuf(nse, &strlength);
if (strlength < 80) {
@@ -1280,7 +1279,7 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
nsock_log_info(ms, "Callback: %s %s for EID %li [%s] %s(%d bytes)%s",
nse_type2str(nse->type), nse_status2str(nse->status),
nse->id,
(nsi->peerlen > 0) ? get_peeraddr_string(nsi) : "peer unspecified",
get_peeraddr_string(nsi),
nse_eof(nse) ? "[EOF]" : "", strlength, displaystr);
}
break;

View File

@@ -75,12 +75,8 @@ nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
if (nsi->peerlen > 0)
nsock_log_info(ms, "Read request for %d lines from IOD #%li [%s] EID %li",
nlines, nsi->id, get_peeraddr_string(nsi), nse->id);
else
nsock_log_info(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li",
nlines, nsi->id, nse->id);
nse->readinfo.read_type = NSOCK_READLINES;
nse->readinfo.num = nlines;
@@ -101,12 +97,8 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
if (nsi->peerlen > 0)
nsock_log_info(ms, "Read request for %d bytes from IOD #%li [%s] EID %li",
nbytes, nsi->id, get_peeraddr_string(nsi), nse->id);
else
nsock_log_info(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li",
nbytes, nsi->id, nse->id);
nse->readinfo.read_type = NSOCK_READBYTES;
nse->readinfo.num = nbytes;
@@ -127,12 +119,8 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler han
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
if (nsi->peerlen > 0)
nsock_log_info(ms, "Read request from IOD #%li [%s] (timeout: %dms) EID %li",
nsi->id, get_peeraddr_string(nsi), timeout_msecs, nse->id);
else
nsock_log_info(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li",
nsi->id, timeout_msecs, nse->id);
nse->readinfo.read_type = NSOCK_READ;

View File

@@ -150,12 +150,9 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
} else {
displaystr[0] = '\0';
}
if (nsi->peerlen > 0)
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s",
datalen, nsi->id, nse->id, get_peeraddr_string(nsi), displaystr);
else
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s",
datalen, nsi->id, nse->id, displaystr);
fs_cat(&nse->iobuf, data, datalen);
@@ -221,12 +218,9 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
} else {
displaystr[0] = '\0';
}
if (nsi->peerlen > 0)
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s",
strlength, nsi->id, nse->id, get_peeraddr_string(nsi), displaystr);
else
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s",
strlength, nsi->id, nse->id, displaystr);
if (buf2 != buf)
free(buf2);