mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 14:39:02 +00:00
Enforce nsock naming scheme.
convert nsp_* calls into nsock_pool_*. Separate words with underscores where appropriate.
This commit is contained in:
18
FPEngine.cc
18
FPEngine.cc
@@ -165,7 +165,7 @@ FPNetworkControl::FPNetworkControl() {
|
||||
FPNetworkControl::~FPNetworkControl() {
|
||||
if (this->nsock_init) {
|
||||
nsock_event_cancel(this->nsp, this->pcap_ev_id, 0);
|
||||
nsp_delete(this->nsp);
|
||||
nsock_pool_delete(this->nsp);
|
||||
this->nsock_init = false;
|
||||
}
|
||||
}
|
||||
@@ -184,23 +184,23 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
||||
}
|
||||
if (this->nsock_init) {
|
||||
nsock_event_cancel(this->nsp, this->pcap_ev_id, 0);
|
||||
nsp_delete(this->nsp);
|
||||
nsock_pool_delete(this->nsp);
|
||||
}
|
||||
|
||||
/* Create a new nsock pool */
|
||||
if ((this->nsp = nsp_new(NULL)) == NULL)
|
||||
if ((this->nsp = nsock_pool_new(NULL)) == NULL)
|
||||
fatal("Unable to obtain an Nsock pool");
|
||||
|
||||
nsock_set_log_function(this->nsp, nmap_nsock_stderr_logger);
|
||||
nmap_adjust_loglevel(this->nsp, o.packetTrace());
|
||||
|
||||
nsp_setdevice(nsp, o.device);
|
||||
nsock_pool_set_device(nsp, o.device);
|
||||
|
||||
if (o.proxy_chain)
|
||||
nsp_set_proxychain(this->nsp, o.proxy_chain);
|
||||
nsock_pool_set_proxychain(this->nsp, o.proxy_chain);
|
||||
|
||||
/* Allow broadcast addresses */
|
||||
nsp_setbroadcast(this->nsp, 1);
|
||||
nsock_pool_set_broadcast(this->nsp, 1);
|
||||
|
||||
/* Allocate an NSI for packet capture */
|
||||
this->pcap_nsi = nsi_new(this->nsp, NULL);
|
||||
@@ -411,7 +411,7 @@ int FPNetworkControl::setup_sniffer(const char *iface, const char *bpf_filter) {
|
||||
fatal("Error opening capture device %s\n", pcapdev);
|
||||
|
||||
/* Store the pcap NSI inside the pool so we can retrieve it inside a callback */
|
||||
nsp_setud(this->nsp, (void *)&(this->pcap_nsi));
|
||||
nsock_pool_set_udata(this->nsp, (void *)&(this->pcap_nsi));
|
||||
|
||||
return OP_SUCCESS;
|
||||
}
|
||||
@@ -440,8 +440,8 @@ int FPNetworkControl::scheduleProbe(FPProbe *pkt, int in_msecs_time) {
|
||||
* The reason for that is because C++ does not allow to use class methods as callback
|
||||
* functions, so this is a small hack to make that happen. */
|
||||
void FPNetworkControl::probe_transmission_handler(nsock_pool nsp, nsock_event nse, void *arg) {
|
||||
assert(nsp_getud(nsp) != NULL);
|
||||
nsock_iod nsi_pcap = *((nsock_iod *)nsp_getud(nsp));
|
||||
assert(nsock_pool_get_udata(nsp) != NULL);
|
||||
nsock_iod nsi_pcap = *((nsock_iod *)nsock_pool_get_udata(nsp));
|
||||
enum nse_status status = nse_status(nse);
|
||||
enum nse_type type = nse_type(nse);
|
||||
FPProbe *myprobe = (FPProbe *)arg;
|
||||
|
||||
@@ -873,7 +873,7 @@ int ncat_connect(void)
|
||||
nsock_set_default_engine("select");
|
||||
|
||||
/* Create an nsock pool */
|
||||
if ((mypool = nsp_new(NULL)) == NULL)
|
||||
if ((mypool = nsock_pool_new(NULL)) == NULL)
|
||||
bye("Failed to create nsock_pool.");
|
||||
|
||||
if (o.debug >= 6)
|
||||
@@ -886,10 +886,10 @@ int ncat_connect(void)
|
||||
nsock_set_loglevel(mypool, NSOCK_LOG_ERROR);
|
||||
|
||||
/* Allow connections to broadcast addresses. */
|
||||
nsp_setbroadcast(mypool, 1);
|
||||
nsock_pool_set_broadcast(mypool, 1);
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
set_ssl_ctx_options((SSL_CTX *) nsp_ssl_init(mypool));
|
||||
set_ssl_ctx_options((SSL_CTX *) nsock_pool_ssl_init(mypool));
|
||||
#endif
|
||||
|
||||
if (!o.proxytype) {
|
||||
@@ -1055,7 +1055,7 @@ int ncat_connect(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
nsp_delete(mypool);
|
||||
nsock_pool_delete(mypool);
|
||||
|
||||
return rc == NSOCK_LOOP_ERROR ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -1213,16 +1213,16 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
|
||||
|
||||
// And finally, do it!
|
||||
|
||||
if ((dnspool = nsp_new(NULL)) == NULL)
|
||||
if ((dnspool = nsock_pool_new(NULL)) == NULL)
|
||||
fatal("Unable to create nsock pool in %s()", __func__);
|
||||
|
||||
nsock_set_log_function(dnspool, nmap_nsock_stderr_logger);
|
||||
nmap_adjust_loglevel(dnspool, o.packetTrace());
|
||||
|
||||
nsp_setdevice(dnspool, o.device);
|
||||
nsock_pool_set_device(dnspool, o.device);
|
||||
|
||||
if (o.proxy_chain)
|
||||
nsp_set_proxychain(dnspool, o.proxy_chain);
|
||||
nsock_pool_set_proxychain(dnspool, o.proxy_chain);
|
||||
|
||||
connect_dns_servers();
|
||||
|
||||
@@ -1251,7 +1251,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
|
||||
|
||||
close_dns_servers();
|
||||
|
||||
nsp_delete(dnspool);
|
||||
nsock_pool_delete(dnspool);
|
||||
|
||||
if (cname_reqs.size() && o.debugging)
|
||||
log_write(LOG_STDOUT, "Performing system-dns for %d domain names that use CNAMEs\n", (int) cname_reqs.size());
|
||||
|
||||
@@ -1445,7 +1445,7 @@ int EchoServer::start() {
|
||||
int rc;
|
||||
|
||||
/* Create a new nsock pool */
|
||||
if ((nsp = nsp_new(NULL)) == NULL)
|
||||
if ((nsp = nsock_pool_new(NULL)) == NULL)
|
||||
nping_fatal(QT_3, "Failed to create new pool. QUITTING.\n");
|
||||
|
||||
/* Set nsock trace level */
|
||||
|
||||
@@ -152,12 +152,12 @@ int ProbeMode::init_nsock(){
|
||||
struct timeval now;
|
||||
if( nsock_init==false ){
|
||||
/* Create a new nsock pool */
|
||||
if ((nsp = nsp_new(NULL)) == NULL)
|
||||
if ((nsp = nsock_pool_new(NULL)) == NULL)
|
||||
nping_fatal(QT_3, "Failed to create new pool. QUITTING.\n");
|
||||
nsp_setdevice(nsp, o.getDevice());
|
||||
nsock_pool_set_device(nsp, o.getDevice());
|
||||
|
||||
/* Allow broadcast addresses */
|
||||
nsp_setbroadcast(nsp, 1);
|
||||
nsock_pool_set_broadcast(nsp, 1);
|
||||
|
||||
/* Set nsock trace level */
|
||||
gettimeofday(&now, NULL);
|
||||
@@ -175,7 +175,7 @@ int ProbeMode::init_nsock(){
|
||||
/** Cleans up the internal nsock pool and any other internal data that
|
||||
* needs to be taken care of before destroying the object. */
|
||||
int ProbeMode::cleanup(){
|
||||
nsp_delete(this->nsp);
|
||||
nsock_pool_delete(this->nsp);
|
||||
return OP_SUCCESS;
|
||||
} /* End of cleanup() */
|
||||
|
||||
|
||||
12
nse_nsock.cc
12
nse_nsock.cc
@@ -70,26 +70,26 @@ static int gc_pool (lua_State *L)
|
||||
{
|
||||
nsock_pool *nsp = (nsock_pool *) lua_touserdata(L, 1);
|
||||
assert(*nsp != NULL);
|
||||
nsp_delete(*nsp);
|
||||
nsock_pool_delete(*nsp);
|
||||
*nsp = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static nsock_pool new_pool (lua_State *L)
|
||||
{
|
||||
nsock_pool nsp = nsp_new(NULL);
|
||||
nsock_pool nsp = nsock_pool_new(NULL);
|
||||
nsock_pool *nspp;
|
||||
|
||||
/* configure logging */
|
||||
nsock_set_log_function(nsp, nmap_nsock_stderr_logger);
|
||||
nmap_adjust_loglevel(nsp, o.scriptTrace());
|
||||
|
||||
nsp_setdevice(nsp, o.device);
|
||||
nsock_pool_set_device(nsp, o.device);
|
||||
|
||||
if (o.proxy_chain)
|
||||
nsp_set_proxychain(nsp, o.proxy_chain);
|
||||
nsock_pool_set_proxychain(nsp, o.proxy_chain);
|
||||
|
||||
nsp_setbroadcast(nsp, true);
|
||||
nsock_pool_set_broadcast(nsp, true);
|
||||
|
||||
nspp = (nsock_pool *) lua_newuserdata(L, sizeof(nsock_pool));
|
||||
*nspp = nsp;
|
||||
@@ -1110,7 +1110,7 @@ LUALIB_API int luaopen_nsock (lua_State *L)
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
/* Value speed over security in SSL connections. */
|
||||
nsp_ssl_init_max_speed(nsp);
|
||||
nsock_pool_ssl_init_max_speed(nsp);
|
||||
#endif
|
||||
|
||||
luaL_newlibtable(L, l_nsock);
|
||||
|
||||
@@ -200,7 +200,7 @@ void nsock_loop_quit(nsock_pool nsp);
|
||||
|
||||
/* This next function returns the errno style error code -- which is only valid
|
||||
* if the status is NSOCK_LOOP_ERROR was returned by nsock_loop() */
|
||||
int nsp_geterrorcode(nsock_pool nsp);
|
||||
int nsock_pool_get_errorcode(nsock_pool nsp);
|
||||
|
||||
nsock_ssl nsi_getssl(nsock_iod nsockiod);
|
||||
|
||||
@@ -214,34 +214,34 @@ nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod);
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside the NSP so
|
||||
* you can retrieve it during a callback. */
|
||||
void nsp_setud(nsock_pool nsp, void *data);
|
||||
void nsock_pool_set_udata(nsock_pool nsp, void *data);
|
||||
|
||||
/* And the function above wouldn't make much sense if we didn't have a way to
|
||||
* retrieve that data ... */
|
||||
void *nsp_getud(nsock_pool nsp);
|
||||
void *nsock_pool_get_udata(nsock_pool nsp);
|
||||
|
||||
/* Turns on or off broadcast support on new sockets. Default is off (0, false)
|
||||
* set in nsp_new(). Any non-zero (true) value sets SO_BROADCAST on all new
|
||||
* sockets (value of optval will be used directly in the setsockopt() call). */
|
||||
void nsp_setbroadcast(nsock_pool nsp, int optval);
|
||||
* set in nsock_pool_new(). Any non-zero (true) value sets SO_BROADCAST on all
|
||||
* new sockets (value of optval will be used directly in the setsockopt() call). */
|
||||
void nsock_pool_set_broadcast(nsock_pool nsp, int optval);
|
||||
|
||||
/* Sets the name of the interface for new sockets to bind to. */
|
||||
void nsp_setdevice(nsock_pool nsp, const char *device);
|
||||
void nsock_pool_set_device(nsock_pool nsp, const char *device);
|
||||
|
||||
/* Initializes an Nsock pool to create SSL connections. This sets an internal
|
||||
* SSL_CTX, which is like a template that sets options for all connections that
|
||||
* are made from it. Returns the SSL_CTX so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool);
|
||||
nsock_ssl_ctx nsock_pool_ssl_init(nsock_pool ms_pool);
|
||||
|
||||
/* Initializes an Nsock pool to create SSL connections that emphasize speed over
|
||||
* security. Insecure ciphers are used when they are faster and no certificate
|
||||
* verification is done. Returns the SSL_CTX so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init_max_speed(nsock_pool ms_pool);
|
||||
nsock_ssl_ctx nsock_pool_ssl_init_max_speed(nsock_pool ms_pool);
|
||||
|
||||
/* Enforce use of a given IO engine.
|
||||
* The engine parameter is a zero-terminated string that will be
|
||||
* strup()'ed by the library. No validity check is performed by this function,
|
||||
* beware nsp_new() will fatal() if an invalid/unavailable engine name was
|
||||
* beware nsock_pool_new() will fatal() if an invalid/unavailable engine name was
|
||||
* supplied before.
|
||||
* Pass NULL to reset to default (use most efficient engine available).
|
||||
*
|
||||
@@ -255,13 +255,13 @@ const char *nsock_list_engines(void);
|
||||
* returns an nsock_pool event aggregator. In the case of error, NULL will be
|
||||
* returned. If you do not wish to immediately associate any userdata, pass in
|
||||
* NULL. */
|
||||
nsock_pool nsp_new(void *userdata);
|
||||
nsock_pool nsock_pool_new(void *udata);
|
||||
|
||||
/* If nsp_new returned success, you must free the nsp when you are done with it
|
||||
/* If nsock_pool_new returned success, you must free the nsp when you are done with it
|
||||
* to conserve memory (and in some cases, sockets). After this call, nsp may no
|
||||
* longer be used. Any pending events are sent an NSE_STATUS_KILL callback and
|
||||
* all outstanding iods are deleted. */
|
||||
void nsp_delete(nsock_pool nsp);
|
||||
void nsock_pool_delete(nsock_pool nsp);
|
||||
|
||||
/* Logging subsystem: set custom logging function.
|
||||
* (See nsock_logger_t type definition). */
|
||||
@@ -273,8 +273,8 @@ void nsock_set_loglevel(nsock_pool nsp, nsock_loglevel_t loglevel);
|
||||
/* Parse a proxy chain description string and build a nsock_proxychain object
|
||||
* accordingly. If the optional nsock_pool parameter is passed in, it gets
|
||||
* associated to the chain object. The alternative is to pass nsp=NULL and call
|
||||
* nsp_set_proxychain() manually. Whatever is done, the chain object has to be
|
||||
* deleted by the caller, using proxychain_delete(). */
|
||||
* nsock_pool_set_proxychain() manually. Whatever is done, the chain object has
|
||||
* to be deleted by the caller, using proxychain_delete(). */
|
||||
int nsock_proxychain_new(const char *proxystr, nsock_proxychain *chain, nsock_pool nspool);
|
||||
|
||||
/* If nsock_proxychain_new() returned success, caller has to free the chain
|
||||
@@ -284,7 +284,7 @@ void nsock_proxychain_delete(nsock_proxychain chain);
|
||||
/* Assign a previously created proxychain object to a nsock pool. After this,
|
||||
* new connections requests will be issued through the chain of proxies (if
|
||||
* possible). */
|
||||
int nsp_set_proxychain(nsock_pool nspool, nsock_proxychain chain);
|
||||
int nsock_pool_set_proxychain(nsock_pool nspool, nsock_proxychain chain);
|
||||
|
||||
/* nsock_event handles a single event. Its ID is generally returned when the
|
||||
* event is created, and the event itself is included in callbacks
|
||||
|
||||
@@ -288,7 +288,7 @@ nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, ns
|
||||
get_unixsock_path(ss), nsi->id, nse->id);
|
||||
|
||||
nsock_connect_internal(ms, nse, SOCK_STREAM, 0, ss, sslen, 0);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
|
||||
@@ -314,7 +314,7 @@ nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod,
|
||||
get_unixsock_path(ss), nsi->id, nse->id);
|
||||
|
||||
nsock_connect_internal(ms, nse, SOCK_DGRAM, 0, ss, sslen, 0);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_hand
|
||||
|
||||
/* Do the actual connect() */
|
||||
nsock_connect_internal(ms, nse, SOCK_STREAM, IPPROTO_TCP, ss, sslen, port);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -371,7 +371,7 @@ nsock_event_id nsock_connect_sctp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_han
|
||||
|
||||
/* Do the actual connect() */
|
||||
nsock_connect_internal(ms, nse, SOCK_STREAM, IPPROTO_SCTP, ss, sslen, port);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -397,7 +397,7 @@ nsock_event_id nsock_connect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
struct nevent *nse;
|
||||
|
||||
if (!ms->sslctx)
|
||||
nsp_ssl_init(ms);
|
||||
nsock_pool_ssl_init(ms);
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
@@ -413,7 +413,7 @@ nsock_event_id nsock_connect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
|
||||
/* Do the actual connect() */
|
||||
nsock_connect_internal(ms, nse, SOCK_STREAM, proto, ss, sslen, port);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
#endif /* HAVE_OPENSSL */
|
||||
@@ -435,7 +435,7 @@ nsock_event_id nsock_reconnect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_han
|
||||
struct nevent *nse;
|
||||
|
||||
if (!ms->sslctx)
|
||||
nsp_ssl_init(ms);
|
||||
nsock_pool_ssl_init(ms);
|
||||
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT_SSL, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
@@ -449,7 +449,7 @@ nsock_event_id nsock_reconnect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_han
|
||||
/* Do the actual connect() */
|
||||
nse->event_done = 0;
|
||||
nse->status = NSE_STATUS_SUCCESS;
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
#endif /* HAVE_OPENSSL */
|
||||
@@ -486,7 +486,7 @@ nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
||||
|
||||
nsock_connect_internal(ms, nse, SOCK_DGRAM, IPPROTO_UDP, ss, sslen, port);
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
|
||||
|
||||
/* At this point the TCP connection is done, whether successful or not.
|
||||
* Therefore decrease the read/write listen counts that were incremented in
|
||||
* nsp_add_event. In the SSL case, we may increase one of the counts depending
|
||||
* nsock_pool_add_event. In the SSL case, we may increase one of the counts depending
|
||||
* on whether SSL_connect returns an error of SSL_ERROR_WANT_READ or
|
||||
* SSL_ERROR_WANT_WRITE. In that case we will re-enter this function, but we
|
||||
* don't want to execute this block again. */
|
||||
@@ -477,7 +477,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
|
||||
|
||||
/* SSLv3-only and TLSv1-only servers can't be connected to when the
|
||||
* SSL_OP_NO_SSLv2 option is not set, which is the case when the pool
|
||||
* was initialized with nsp_ssl_init_max_speed. Try reconnecting with
|
||||
* was initialized with nsock_pool_ssl_init_max_speed. Try reconnecting with
|
||||
* SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one that
|
||||
* might use SSLv2. */
|
||||
nsock_log_info(ms, "EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id);
|
||||
@@ -1237,7 +1237,7 @@ const struct timeval *nsock_gettimeofday() {
|
||||
/* Adds an event to the appropriate nsp event list, handles housekeeping such as
|
||||
* adjusting the descriptor select/poll lists, registering the timeout value,
|
||||
* etc. */
|
||||
void nsp_add_event(struct npool *nsp, struct nevent *nse) {
|
||||
void nsock_pool_add_event(struct npool *nsp, struct nevent *nse) {
|
||||
nsock_log_debug(nsp, "NSE #%lu: Adding event (timeout in %ldms)",
|
||||
nse->id,
|
||||
(long)TIMEVAL_MSEC_SUBTRACT(nse->timeout, nsock_tod));
|
||||
|
||||
@@ -209,7 +209,7 @@ struct npool {
|
||||
#endif
|
||||
|
||||
/* Optional proxy chain (NULL is not set). Can only be set once per NSP (using
|
||||
* nsock_proxychain_new() or nsp_set_proxychain(). */
|
||||
* nsock_proxychain_new() or nsock_pool_set_proxychain(). */
|
||||
struct proxy_chain *px_chain;
|
||||
|
||||
};
|
||||
@@ -458,7 +458,7 @@ void event_delete(struct npool *nsp, struct nevent *nse);
|
||||
/* Add an event to the appropriate nsp event list, handles housekeeping such as
|
||||
* adjusting the descriptor select/poll lists, registering the timeout value,
|
||||
* etc. */
|
||||
void nsp_add_event(struct npool *nsp, struct nevent *nse);
|
||||
void nsock_pool_add_event(struct npool *nsp, struct nevent *nse);
|
||||
|
||||
void nsock_connect_internal(struct npool *ms, struct nevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen, unsigned short port);
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ nsock_event_id nsock_pcap_read_packet(nsock_pool nsp, nsock_iod nsiod,
|
||||
|
||||
nsock_log_info(ms, "Pcap read request from IOD #%li EID %li", nsi->id, nse->id);
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
@@ -89,35 +89,35 @@ static void nsock_library_initialize(void);
|
||||
|
||||
/* This next function returns the errno style error code -- which is only
|
||||
* valid if the status NSOCK_LOOP_ERROR was returned by nsock_loop() */
|
||||
int nsp_geterrorcode(nsock_pool nsp) {
|
||||
int nsock_pool_get_errorcode(nsock_pool nsp) {
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
return mt->errnum;
|
||||
}
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside
|
||||
* the NSP so you can retrieve it during a callback. */
|
||||
void nsp_setud(nsock_pool nsp, void *data) {
|
||||
void nsock_pool_set_udata(nsock_pool nsp, void *data) {
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->userdata = data;
|
||||
}
|
||||
|
||||
/* And the define above wouldn't make much sense if we didn't have a way
|
||||
* to retrieve that data ... */
|
||||
void *nsp_getud(nsock_pool nsp) {
|
||||
void *nsock_pool_get_udata(nsock_pool nsp) {
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
return mt->userdata;
|
||||
}
|
||||
|
||||
/* Turns on or off broadcast support on new sockets. Default is off (0, false)
|
||||
* set in nsp_new(). Any non-zero (true) value sets SO_BROADCAST on all new
|
||||
* set in nsock_pool_new(). Any non-zero (true) value sets SO_BROADCAST on all new
|
||||
* sockets (value of optval will be used directly in the setsockopt() call */
|
||||
void nsp_setbroadcast(nsock_pool nsp, int optval) {
|
||||
void nsock_pool_set_broadcast(nsock_pool nsp, int optval) {
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->broadcast = optval;
|
||||
}
|
||||
|
||||
/* Sets the name of the interface for new sockets to bind to. */
|
||||
void nsp_setdevice(nsock_pool nsp, const char *device) {
|
||||
void nsock_pool_set_device(nsock_pool nsp, const char *device) {
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->device = device;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ static int expirable_cmp(gh_hnode_t *n1, gh_hnode_t *n2) {
|
||||
* returns an nsock_pool event aggregator. In the case of error, NULL will be
|
||||
* returned. If you do not wish to immediately associate any userdata, pass in
|
||||
* NULL. */
|
||||
nsock_pool nsp_new(void *userdata) {
|
||||
nsock_pool nsock_pool_new(void *userdata) {
|
||||
struct npool *nsp;
|
||||
|
||||
/* initialize the library in not already done */
|
||||
@@ -189,11 +189,11 @@ nsock_pool nsp_new(void *userdata) {
|
||||
return (nsock_pool)nsp;
|
||||
}
|
||||
|
||||
/* If nsp_new returned success, you must free the nsp when you are done with it
|
||||
/* If nsock_pool_new returned success, you must free the nsp when you are done with it
|
||||
* to conserve memory (and in some cases, sockets). After this call, nsp may no
|
||||
* longer be used. Any pending events are sent an NSE_STATUS_KILL callback and
|
||||
* all outstanding iods are deleted. */
|
||||
void nsp_delete(nsock_pool ms_pool) {
|
||||
void nsock_pool_delete(nsock_pool ms_pool) {
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct nevent *nse;
|
||||
struct niod *nsi;
|
||||
|
||||
@@ -109,7 +109,7 @@ int nsock_proxychain_new(const char *proxystr, nsock_proxychain *chain, nsock_po
|
||||
}
|
||||
|
||||
if (nsp) {
|
||||
if (nsp_set_proxychain(nspool, pxc) < 0) {
|
||||
if (nsock_pool_set_proxychain(nspool, pxc) < 0) {
|
||||
nsock_proxychain_delete(pxc);
|
||||
return -1;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ void nsock_proxychain_delete(nsock_proxychain chain) {
|
||||
}
|
||||
}
|
||||
|
||||
int nsp_set_proxychain(nsock_pool nspool, nsock_proxychain chain) {
|
||||
int nsock_pool_set_proxychain(nsock_pool nspool, nsock_proxychain chain) {
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
|
||||
if (nsp && nsp->px_chain) {
|
||||
|
||||
@@ -81,7 +81,7 @@ nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nse->readinfo.read_type = NSOCK_READLINES;
|
||||
nse->readinfo.num = nlines;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nse->readinfo.read_type = NSOCK_READBYTES;
|
||||
nse->readinfo.num = nbytes;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod,
|
||||
|
||||
nse->readinfo.read_type = NSOCK_READ;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
nsock_pool_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@
|
||||
|
||||
extern struct timeval nsock_tod;
|
||||
|
||||
/* Create an SSL_CTX and do initialization that is common to nsp_ssl_init and
|
||||
* nsp_ssl_init_max_speed. */
|
||||
/* Create an SSL_CTX and do initialization that is common to nsock_pool_ssl_init and
|
||||
* nsock_pool_ssl_init_max_speed. */
|
||||
static SSL_CTX *ssl_init_common() {
|
||||
SSL_CTX *ctx;
|
||||
|
||||
@@ -109,7 +109,7 @@ static SSL_CTX *ssl_init_common() {
|
||||
* are made from it. The connections made from this context will use only secure
|
||||
* ciphers but no server certificate verification is done. Returns the SSL_CTX
|
||||
* so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
nsock_ssl_ctx nsock_pool_ssl_init(nsock_pool ms_pool) {
|
||||
struct npool *ms = (struct npool *)ms_pool;
|
||||
char rndbuf[128];
|
||||
|
||||
@@ -123,7 +123,7 @@ nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
get_random_bytes(rndbuf, sizeof(rndbuf));
|
||||
RAND_add(rndbuf, sizeof(rndbuf), 0);
|
||||
if (!RAND_status())
|
||||
fatal("nsp_ssl_init: Failed to seed OpenSSL PRNG (RAND_status returned false).");
|
||||
fatal("nsock_pool_ssl_init: Failed to seed OpenSSL PRNG (RAND_status returned false).");
|
||||
|
||||
/* By default, do no server certificate verification. To enable it, do
|
||||
* something like:
|
||||
@@ -151,7 +151,7 @@ nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
/* Initializes an Nsock pool to create SSL connections that emphasize speed over
|
||||
* security. Insecure ciphers are used when they are faster and no certificate
|
||||
* verification is done. Returns the SSL_CTX so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
nsock_ssl_ctx nsock_pool_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
struct npool *ms = (struct npool *)ms_pool;
|
||||
char rndbuf[128];
|
||||
|
||||
@@ -201,11 +201,11 @@ int nsi_ssl_post_connect_verify(const nsock_iod nsockiod) {
|
||||
|
||||
#else /* NOT HAVE_OPENSSL */
|
||||
|
||||
nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
nsock_ssl_ctx nsock_pool_ssl_init(nsock_pool ms_pool) {
|
||||
fatal("%s called with no OpenSSL support", __func__);
|
||||
}
|
||||
|
||||
nsock_ssl_ctx nsp_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
nsock_ssl_ctx nsock_pool_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
fatal("%s called with no OpenSSL support", __func__);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ nsock_event_id nsock_timer_create(nsock_pool ms_pool, nsock_ev_handler handler,
|
||||
nsock_log_info(nsp, "Timer created - %dms from now. EID %li", timeout_msecs,
|
||||
nse->id);
|
||||
|
||||
nsp_add_event(nsp, nse);
|
||||
nsock_pool_add_event(nsp, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
|
||||
|
||||
fs_cat(&nse->iobuf, data, datalen);
|
||||
|
||||
nsp_add_event(nsp, nse);
|
||||
nsock_pool_add_event(nsp, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
|
||||
fs_cat(&nse->iobuf, data, datalen);
|
||||
|
||||
nsp_add_event(nsp, nse);
|
||||
nsock_pool_add_event(nsp, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
if (buf2 != buf)
|
||||
free(buf2);
|
||||
|
||||
nsp_add_event(nsp, nse);
|
||||
nsock_pool_add_event(nsp, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
@@ -2272,7 +2272,7 @@ static void servicescan_connect_handler(nsock_pool nsp, nsock_event nse, void *m
|
||||
enum nse_type type = nse_type(nse);
|
||||
ServiceNFO *svc = (ServiceNFO *) mydata;
|
||||
ServiceProbe *probe = svc->currentProbe();
|
||||
ServiceGroup *SG = (ServiceGroup *) nsp_getud(nsp);
|
||||
ServiceGroup *SG = (ServiceGroup *) nsock_pool_get_udata(nsp);
|
||||
|
||||
assert(type == NSE_TYPE_CONNECT || type == NSE_TYPE_CONNECT_SSL);
|
||||
|
||||
@@ -2341,7 +2341,7 @@ static void servicescan_write_handler(nsock_pool nsp, nsock_event nse, void *myd
|
||||
ServiceGroup *SG;
|
||||
int err;
|
||||
|
||||
SG = (ServiceGroup *) nsp_getud(nsp);
|
||||
SG = (ServiceGroup *) nsock_pool_get_udata(nsp);
|
||||
nsi = nse_iod(nse);
|
||||
|
||||
// Check if a status message was requested
|
||||
@@ -2390,7 +2390,7 @@ static void servicescan_read_handler(nsock_pool nsp, nsock_event nse, void *myda
|
||||
enum nse_type type = nse_type(nse);
|
||||
ServiceNFO *svc = (ServiceNFO *) mydata;
|
||||
ServiceProbe *probe = svc->currentProbe();
|
||||
ServiceGroup *SG = (ServiceGroup *) nsp_getud(nsp);
|
||||
ServiceGroup *SG = (ServiceGroup *) nsock_pool_get_udata(nsp);
|
||||
const u8 *readstr;
|
||||
int readstrlen;
|
||||
const struct MatchDetails *MD;
|
||||
@@ -2752,21 +2752,21 @@ int service_scan(std::vector<Target *> &Targets) {
|
||||
|
||||
// Lets create a nsock pool for managing all the concurrent probes
|
||||
// Store the servicegroup in there for availability in callbacks
|
||||
if ((nsp = nsp_new(SG)) == NULL) {
|
||||
if ((nsp = nsock_pool_new(SG)) == NULL) {
|
||||
fatal("%s() failed to create new nsock pool.", __func__);
|
||||
}
|
||||
nsock_set_log_function(nsp, nmap_nsock_stderr_logger);
|
||||
nmap_adjust_loglevel(nsp, o.versionTrace());
|
||||
|
||||
nsp_setdevice(nsp, o.device);
|
||||
nsock_pool_set_device(nsp, o.device);
|
||||
|
||||
if (o.proxy_chain) {
|
||||
nsp_set_proxychain(nsp, o.proxy_chain);
|
||||
nsock_pool_set_proxychain(nsp, o.proxy_chain);
|
||||
}
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
/* We don't care about connection security in version detection. */
|
||||
nsp_ssl_init_max_speed(nsp);
|
||||
nsock_pool_ssl_init_max_speed(nsp);
|
||||
#endif
|
||||
|
||||
launchSomeServiceProbes(nsp, SG);
|
||||
@@ -2778,11 +2778,11 @@ int service_scan(std::vector<Target *> &Targets) {
|
||||
// OK! Lets start our main loop!
|
||||
looprc = nsock_loop(nsp, timeout);
|
||||
if (looprc == NSOCK_LOOP_ERROR) {
|
||||
int err = nsp_geterrorcode(nsp);
|
||||
int err = nsock_pool_get_errorcode(nsp);
|
||||
fatal("Unexpected nsock_loop error. Error code %d (%s)", err, socket_strerror(err));
|
||||
}
|
||||
|
||||
nsp_delete(nsp);
|
||||
nsock_pool_delete(nsp);
|
||||
|
||||
if (o.verbose) {
|
||||
char additional_info[128];
|
||||
|
||||
Reference in New Issue
Block a user