1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 21:21:31 +00:00

Abstract nsock logging function to avoid nsock.h inclusion in output.h

This commit is contained in:
dmiller
2020-01-11 16:03:28 +00:00
parent 6ed754b438
commit a2c75e0ef4
6 changed files with 11 additions and 7 deletions

View File

@@ -206,7 +206,7 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
if ((this->nsp = nsock_pool_new(NULL)) == NULL)
fatal("Unable to obtain an Nsock pool");
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_set_nsock_logger();
nmap_adjust_loglevel(o.packetTrace());
nsock_pool_set_device(nsp, o.device);

View File

@@ -1190,7 +1190,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
if ((dnspool = nsock_pool_new(NULL)) == NULL)
fatal("Unable to create nsock pool in %s()", __func__);
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_set_nsock_logger();
nmap_adjust_loglevel(o.packetTrace());
nsock_pool_set_device(dnspool, o.device);

View File

@@ -85,7 +85,7 @@ static nsock_pool new_pool (lua_State *L)
nsock_pool *nspp;
/* configure logging */
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_set_nsock_logger();
nmap_adjust_loglevel(o.scriptTrace());
nsock_pool_set_device(nsp, o.device);

View File

@@ -151,6 +151,7 @@
#include "xml.h"
#include "nbase.h"
#include "libnetutil/netutil.h"
#include <nsock.h>
#include <math.h>
@@ -2782,7 +2783,7 @@ void nmap_adjust_loglevel(bool trace) {
nsock_set_loglevel(nsock_loglevel);
}
void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec) {
static void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec) {
int elapsed_time;
elapsed_time = TIMEVAL_MSEC_SUBTRACT(rec->time, *(o.getStartTime()));
@@ -2790,3 +2791,7 @@ void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec) {
log_write(LOG_STDERR, "NSOCK %s [%.4fs] %s(): %s\n", nslog2str(rec->level),
elapsed_time/1000.0, rec->func, rec->msg);
}
void nmap_set_nsock_logger() {
nsock_set_log_function(nmap_nsock_stderr_logger);
}

View File

@@ -173,7 +173,6 @@
#ifndef NOLUA
#include "nse_main.h"
#endif
#include <nsock.h>
class PortList;
class Target;
@@ -311,7 +310,7 @@ void printdatafilepaths();
/* nsock logging interface */
void nmap_adjust_loglevel(bool trace);
void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec);
void nmap_set_nsock_logger();
#endif /* OUTPUT_H */

View File

@@ -2851,7 +2851,7 @@ int service_scan(std::vector<Target *> &Targets) {
if ((nsp = nsock_pool_new(SG)) == NULL) {
fatal("%s() failed to create new nsock pool.", __func__);
}
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_set_nsock_logger();
nmap_adjust_loglevel(o.versionTrace());
nsock_pool_set_device(nsp, o.device);