diff --git a/CHANGELOG b/CHANGELOG
index b55396a87..2b2ee9bd1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,8 @@
# Nmap Changelog ($Id$); -*-text-*-
+o Added a --nsock-engine option to nmap, nping and ncat to enforce use of a
+ given nsock IO engine. [Henri]
+
o [NSE] Added support to broadcast-listener for extracting address, native vlan
and management IP address from CDP packets. [Tom]
diff --git a/docs/refguide.xml b/docs/refguide.xml
index bcf38e31a..fcb70f0b3 100644
--- a/docs/refguide.xml
+++ b/docs/refguide.xml
@@ -2860,6 +2860,23 @@ worth the extra time.
+
+ --nsock-engine
+ epoll|select
+ --nsock-engine
+ Nsock IO engine
+
+
+
+Enforce use of a given nsock IO multiplexing engine. Only the
+select(2) -based fallback engine is guaranteed to be
+available on your system. Engines are named after the name of the IO
+management facility they leverage. Engines currenty implemented are
+epoll and select .
+
+
+
+
-T
diff --git a/ncat/ncat_main.c b/ncat/ncat_main.c
index c136c050d..21cd2403d 100644
--- a/ncat/ncat_main.c
+++ b/ncat/ncat_main.c
@@ -262,6 +262,7 @@ int main(int argc, char *argv[])
{"proxy", required_argument, NULL, 0},
{"proxy-type", required_argument, NULL, 0},
{"proxy-auth", required_argument, NULL, 0},
+ {"nsock-engine", required_argument, NULL, 0},
#ifdef HAVE_OPENSSL
{"ssl", no_argument, &o.ssl, 1},
{"ssl-cert", required_argument, NULL, 0},
@@ -412,6 +413,10 @@ int main(int argc, char *argv[])
bye("You can't specify more than one --proxy-auth.");
o.proxy_auth = Strdup(optarg);
}
+ else if (strcmp(long_options[option_index].name, "nsock-engine") == 0)
+ {
+ nsock_set_default_engine(optarg);
+ }
else if (strcmp(long_options[option_index].name, "broker") == 0)
{
o.broker = 1;
diff --git a/nmap.cc b/nmap.cc
index cc9d71ea9..c6b0a5c9c 100644
--- a/nmap.cc
+++ b/nmap.cc
@@ -573,6 +573,8 @@ void parse_options(int argc, char **argv) {
{"source-port", required_argument, 0, 'g'},
{"randomize_hosts", no_argument, 0, 0},
{"randomize-hosts", no_argument, 0, 0},
+ {"nsock_engine", required_argument, 0, 0},
+ {"nsock-engine", required_argument, 0, 0},
{"osscan_limit", no_argument, 0, 0}, /* skip OSScan if no open ports */
{"osscan-limit", no_argument, 0, 0}, /* skip OSScan if no open ports */
{"osscan_guess", no_argument, 0, 0}, /* More guessing flexability */
@@ -793,6 +795,8 @@ void parse_options(int argc, char **argv) {
|| strcmp(long_options[option_index].name, "rH") == 0) {
o.randomize_hosts = 1;
o.ping_group_sz = PING_GROUP_SZ * 4;
+ } else if (optcmp(long_options[option_index].name, "nsock-engine") == 0) {
+ nsock_set_default_engine(optarg);
} else if (optcmp(long_options[option_index].name, "osscan-limit") == 0) {
o.osscan_limit = 1;
} else if (optcmp(long_options[option_index].name, "osscan-guess") == 0
@@ -2111,6 +2115,7 @@ void nmap_free_mem() {
free_services();
AllProbes::service_scan_free();
traceroute_hop_cache_clear();
+ nsock_set_default_engine(NULL);
}
/* Reads in a (normal or machine format) Nmap log file and gathers enough
diff --git a/nping/ArgParser.cc b/nping/ArgParser.cc
index 54a2fe6fa..06518fb7e 100644
--- a/nping/ArgParser.cc
+++ b/nping/ArgParser.cc
@@ -271,6 +271,7 @@ char errstr[256];
{"send-ip", no_argument, 0, 0},
{"bpf-filter", required_argument, 0, 0},
{"filter", required_argument, 0, 0},
+ {"nsock-engine", required_argument, 0, 0},
{"no-capture", no_argument, 0, 'N'},
{"hide-sent", no_argument, 0, 'H'},
@@ -954,7 +955,9 @@ char errstr[256];
o.setBPFFilterSpec( optarg );
if( o.issetDisablePacketCapture() && o.disablePacketCapture()==true )
outError(QT_2, "Warning: There is no point on specifying a BPF filter if you disable packet capture. BPF filter will be ignored.");
-
+ } else if (optcmp(long_options[option_index].name, "nsock-engine") == 0){
+ nsock_set_default_engine(optarg);
+
/* Output Options */
} else if (optcmp(long_options[option_index].name, "quiet") == 0 ){
o.setVerbosity(-4);
diff --git a/nsock/include/nsock.h b/nsock/include/nsock.h
index 38c0db55e..8f2a7fa69 100644
--- a/nsock/include/nsock.h
+++ b/nsock/include/nsock.h
@@ -193,6 +193,14 @@ nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool);
* 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);
+/* 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
+ * supplied before.
+ * Pass NULL to reset to default (use most efficient engine available). */
+void nsock_set_default_engine(char *engine);
+
/* And here is how you create an nsock_pool. This allocates, initializes, and
* 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
diff --git a/nsock/src/nsock_engines.c b/nsock/src/nsock_engines.c
index c0517d759..a13b5e23c 100644
--- a/nsock/src/nsock_engines.c
+++ b/nsock/src/nsock_engines.c
@@ -83,8 +83,10 @@ static struct io_engine *available_engines[] = {
NULL
};
+static char *engine_hint;
-struct io_engine *get_io_engine(const char *engine_hint) {
+
+struct io_engine *get_io_engine(void) {
struct io_engine *engine = NULL;
int i;
@@ -105,3 +107,13 @@ struct io_engine *get_io_engine(const char *engine_hint) {
return engine;
}
+void nsock_set_default_engine(char *engine) {
+ if (engine_hint)
+ free(engine_hint);
+
+ if (engine)
+ engine_hint = strdup(engine);
+ else
+ engine_hint = NULL;
+}
+
diff --git a/nsock/src/nsock_pool.c b/nsock/src/nsock_pool.c
index 06e2d0236..55ed0841d 100644
--- a/nsock/src/nsock_pool.c
+++ b/nsock/src/nsock_pool.c
@@ -81,7 +81,7 @@ static int nsocklib_initialized = 0;
/* defined in nsock_engines.h */
-struct io_engine *get_io_engine(const char *engine_hint);
+struct io_engine *get_io_engine(void);
/* ---- INTERNAL FUNCTIONS PROTOTYPES ---- */
static void nsock_library_initialize(void);
@@ -170,7 +170,7 @@ nsock_pool nsp_new(void *userdata) {
nsp->userdata = userdata;
- nsp->engine = get_io_engine(NULL);
+ nsp->engine = get_io_engine();
nsp->engine->init(nsp);
/* initialize IO events lists */