Nmap Development mailing list archives

Re: [nmap-svn] r36171 - in nmap: nbase nsock nsock/include nsock/src


From: Tudor-Emil COMAN <tudor_emil.coman () cti pub ro>
Date: Mon, 22 Aug 2016 20:27:32 +0000

Hi,


Thanks for the feedback!

I fixed these compiler warnings in rev 36173.


Cheers,

Tudor

________________________________
From: Daniel Miller <bonsaiviking () gmail com>
Sent: Monday, August 22, 2016 11:12:44 PM
To: Tudor-Emil COMAN
Cc: Nmap-dev
Subject: Re: [nmap-svn] r36171 - in nmap: nbase nsock nsock/include nsock/src

Tudor,

This is exciting that we're merging IOCP again! I did spot a few warnings during compilation that we should clean up:

src\engine_iocp.c(203): warning C4101: 'next' : unreferenced local variable

Probably just remove this.

src\engine_iocp.c(298): warning C4018: '<' : signed/unsigned mismatch

Here we should probably check for positive number then cast it to unsigned for the comparison: if (total_events > 0 && 
iinfo->capacity < (unsigned long) total_events); But I'm not positive that is the best solution?

src\engine_iocp.c(364): warning C4018: '<' : signed/unsigned mismatch

This loop variable should be changed to "unsigned long" to match the number it's counting up to.

src\engine_iocp.c(758): warning C4806: '==' : unsafe operation: no value of type 'bool' promoted to type 'nse_type' can 
equal the given constant

You need to use "nse->type !=" instead of "!nse->type ==" here, because the ! has higher precedence than the ==, so 
you're comparing either true == NSE_TYPE_READ or false == NSE_TYPE_READ, neither of which can ever be true.

I'll let you know if I spot anything else in my testing.

Dan

On Mon, Aug 22, 2016 at 2:15 PM, <commit-mailer () nmap org<mailto:commit-mailer () nmap org>> wrote:
Author: tudor
Date: Mon Aug 22 12:15:13 2016
New Revision: 36171

Log:
Added IOCP integration for Nsock, engine IOCP is the default engine on Windows

Added:
   nmap/nsock/src/engine_iocp.c
      - copied unchanged from r36170, /nmap-exp/tudor/nsock-iocp/nsock/src/engine_iocp.c
Modified:
   nmap/nbase/nbase_misc.c   (contents, props changed)
   nmap/nsock/include/nsock_winconfig.h
   nmap/nsock/nsock.vcxproj
   nmap/nsock/src/engine_epoll.c
   nmap/nsock/src/engine_kqueue.c
   nmap/nsock/src/engine_poll.c
   nmap/nsock/src/engine_select.c
   nmap/nsock/src/nsock_connect.c
   nmap/nsock/src/nsock_core.c
   nmap/nsock/src/nsock_engines.c
   nmap/nsock/src/nsock_internal.h

Modified: nmap/nbase/nbase_misc.c
==============================================================================
--- nmap/nbase/nbase_misc.c     (original)
+++ nmap/nbase/nbase_misc.c     Mon Aug 22 12:15:13 2016
@@ -257,7 +257,7 @@
   /* WSASocket is just like socket, except that the sockets it creates are
      inheritable by subprocesses (such as are created by CreateProcess), while
      those created by socket are not. */
-  return WSASocket(af, style, protocol, NULL, 0, 0);
+  return WSASocket(af, style, protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
 #else
   return socket(af, style, protocol);
 #endif

Modified: nmap/nsock/include/nsock_winconfig.h
==============================================================================
--- nmap/nsock/include/nsock_winconfig.h        (original)
+++ nmap/nsock/include/nsock_winconfig.h        Mon Aug 22 12:15:13 2016
@@ -102,6 +102,7 @@
  /* WSAPoll() isn't available before Vista */
 #if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
 #define HAVE_POLL 1
+#define HAVE_IOCP 1
 #endif

 #endif /* NSOCK_WINCONFIG_H */

Modified: nmap/nsock/nsock.vcxproj
==============================================================================
--- nmap/nsock/nsock.vcxproj    (original)
+++ nmap/nsock/nsock.vcxproj    Mon Aug 22 12:15:13 2016
@@ -186,6 +186,7 @@
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="src\engine_epoll.c" />
+    <ClCompile Include="src\engine_iocp.c" />
     <ClCompile Include="src\engine_kqueue.c" />
     <ClCompile Include="src\engine_poll.c" />
     <ClCompile Include="src\engine_select.c" />

Modified: nmap/nsock/src/engine_epoll.c
==============================================================================
--- nmap/nsock/src/engine_epoll.c       (original)
+++ nmap/nsock/src/engine_epoll.c       Mon Aug 22 12:15:13 2016
@@ -85,11 +85,12 @@
 /* --- ENGINE INTERFACE PROTOTYPES --- */
 static int epoll_init(struct npool *nsp);
 static void epoll_destroy(struct npool *nsp);
-static int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev);
+static int epoll_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev);
 static int epoll_iod_unregister(struct npool *nsp, struct niod *iod);
-static int epoll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
+static int epoll_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr);
 static int epoll_loop(struct npool *nsp, int msec_timeout);

+extern struct io_operations posix_io_operations;

 /* ---- ENGINE DEFINITION ---- */
 struct io_engine engine_epoll = {
@@ -99,7 +100,8 @@
   epoll_iod_register,
   epoll_iod_unregister,
   epoll_iod_modify,
-  epoll_loop
+  epoll_loop,
+  &posix_io_operations
 };


@@ -159,7 +161,7 @@
   free(einfo);
 }

-int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
+int epoll_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev) {
   int sd;
   struct epoll_event epev;
   struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
@@ -204,7 +206,7 @@
   return 1;
 }

-int epoll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
+int epoll_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr) {
   int sd;
   struct epoll_event epev;
   int new_events;

Modified: nmap/nsock/src/engine_kqueue.c
==============================================================================
--- nmap/nsock/src/engine_kqueue.c      (original)
+++ nmap/nsock/src/engine_kqueue.c      Mon Aug 22 12:15:13 2016
@@ -78,11 +78,12 @@
 /* --- ENGINE INTERFACE PROTOTYPES --- */
 static int kqueue_init(struct npool *nsp);
 static void kqueue_destroy(struct npool *nsp);
-static int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev);
+static int kqueue_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev);
 static int kqueue_iod_unregister(struct npool *nsp, struct niod *iod);
-static int kqueue_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
+static int kqueue_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr);
 static int kqueue_loop(struct npool *nsp, int msec_timeout);

+extern struct io_operations posix_io_operations;

 /* ---- ENGINE DEFINITION ---- */
 struct io_engine engine_kqueue = {
@@ -92,7 +93,8 @@
   kqueue_iod_register,
   kqueue_iod_unregister,
   kqueue_iod_modify,
-  kqueue_loop
+  kqueue_loop,
+  &posix_io_operations
 };


@@ -151,7 +153,7 @@
   free(kinfo);
 }

-int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev) {
+int kqueue_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev) {
   struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;

   assert(!IOD_PROPGET(iod, IOD_REGISTERED));
@@ -185,7 +187,7 @@

 #define EV_SETFLAG(_set, _ev) (((_set) & (_ev)) ? (EV_ADD|EV_ENABLE) : (EV_ADD|EV_DISABLE))

-int kqueue_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
+int kqueue_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr) {
   struct kevent kev[2];
   int new_events, i;
   struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;

Modified: nmap/nsock/src/engine_poll.c
==============================================================================
--- nmap/nsock/src/engine_poll.c        (original)
+++ nmap/nsock/src/engine_poll.c        Mon Aug 22 12:15:13 2016
@@ -106,13 +106,14 @@
   #define POLL_X_FLAGS (POLLERR | POLLHUP)
 #endif /* POLLRDHUP */

+extern struct io_operations posix_io_operations;

 /* --- ENGINE INTERFACE PROTOTYPES --- */
 static int poll_init(struct npool *nsp);
 static void poll_destroy(struct npool *nsp);
-static int poll_iod_register(struct npool *nsp, struct niod *iod, int ev);
+static int poll_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev);
 static int poll_iod_unregister(struct npool *nsp, struct niod *iod);
-static int poll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
+static int poll_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr);
 static int poll_loop(struct npool *nsp, int msec_timeout);


@@ -124,7 +125,8 @@
   poll_iod_register,
   poll_iod_unregister,
   poll_iod_modify,
-  poll_loop
+  poll_loop,
+  &posix_io_operations
 };


@@ -212,7 +214,7 @@
   free(pinfo);
 }

-int poll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
+int poll_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev) {
   struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
   int sd;

@@ -265,7 +267,7 @@
   return 1;
 }

-int poll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
+int poll_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr) {
   int sd;
   int new_events;
   struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;

Modified: nmap/nsock/src/engine_select.c
==============================================================================
--- nmap/nsock/src/engine_select.c      (original)
+++ nmap/nsock/src/engine_select.c      Mon Aug 22 12:15:13 2016
@@ -67,13 +67,15 @@
 #include "nsock_pcap.h"
 #endif

+extern struct io_operations posix_io_operations;
+

 /* --- ENGINE INTERFACE PROTOTYPES --- */
 static int select_init(struct npool *nsp);
 static void select_destroy(struct npool *nsp);
-static int select_iod_register(struct npool *nsp, struct niod *iod, int ev);
+static int select_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev);
 static int select_iod_unregister(struct npool *nsp, struct niod *iod);
-static int select_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
+static int select_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr);
 static int select_loop(struct npool *nsp, int msec_timeout);


@@ -85,7 +87,8 @@
   select_iod_register,
   select_iod_unregister,
   select_iod_modify,
-  select_loop
+  select_loop,
+  &posix_io_operations
 };


@@ -153,11 +156,11 @@
   free(nsp->engine_data);
 }

-int select_iod_register(struct npool *nsp, struct niod *iod, int ev) {
+int select_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev) {
   assert(!IOD_PROPGET(iod, IOD_REGISTERED));

   iod->watched_events = ev;
-  select_iod_modify(nsp, iod, ev, EV_NONE);
+  select_iod_modify(nsp, iod, nse, ev, EV_NONE);
   IOD_PROPSET(iod, IOD_REGISTERED);
   return 1;
 }
@@ -196,7 +199,7 @@
   return 1;
 }

-int select_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
+int select_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr) {
   int sd;
   struct select_engine_info *sinfo = (struct select_engine_info *)nsp->engine_data;


Modified: nmap/nsock/src/nsock_connect.c
==============================================================================
--- nmap/nsock/src/nsock_connect.c      (original)
+++ nmap/nsock/src/nsock_connect.c      Mon Aug 22 12:15:13 2016
@@ -253,7 +253,7 @@
       memcpy(&iod->peer, ss, sslen);
     iod->peerlen = sslen;

-    if (connect(iod->sd, (struct sockaddr *)ss, sslen) == -1) {
+    if (ms->engine->io_operations->iod_connect(ms, iod->sd, (struct sockaddr *)ss, sslen) == -1) {
       int err = socket_errno();

       if (proto == IPPROTO_UDP || (err != EINPROGRESS && err != EAGAIN)) {

Modified: nmap/nsock/src/nsock_core.c
==============================================================================
--- nmap/nsock/src/nsock_core.c (original)
+++ nmap/nsock/src/nsock_core.c Mon Aug 22 12:15:13 2016
@@ -86,7 +86,6 @@
 #include "nsock_pcap.h"
 #endif

-
 /* Nsock time of day -- we update this at least once per nsock_loop round (and
  * after most calls that are likely to block).  Other nsock files should grab
  * this */
@@ -178,7 +177,7 @@
  * If this counter reaches zero, the event won't be watched anymore by the
  * IO engine for this IOD.
  */
-static void update_events(struct niod * iod, struct npool *ms, int ev_inc, int ev_dec) {
+static void update_events(struct niod * iod, struct npool *ms, struct nevent *nse, int ev_inc, int ev_dec) {
   int setmask, clrmask, ev_temp;

   /* Filter out events that belong to both sets. */
@@ -204,9 +203,9 @@

   if (!IOD_PROPGET(iod, IOD_REGISTERED)) {
     assert(clrmask == EV_NONE);
-    nsock_engine_iod_register(ms, iod, setmask);
+    nsock_engine_iod_register(ms, iod, nse, setmask);
   } else {
-    nsock_engine_iod_modify(ms, iod, setmask, clrmask);
+    nsock_engine_iod_modify(ms, iod, nse, setmask, clrmask);
   }
 }

@@ -287,6 +286,7 @@
     default:
       fatal("Unknown event type (%d) for IOD #%lu\n", nse->type, iod->id);
   }
+
   return 0;
 }

@@ -427,7 +427,7 @@
     ev |= socket_count_read_dec(iod);
     ev |= socket_count_write_dec(iod);
     ev |= EV_EXCEPT;
-    update_events(iod, ms, EV_NONE, ev);
+    update_events(iod, ms, nse, EV_NONE, ev);
   }

 #if HAVE_OPENSSL
@@ -446,7 +446,7 @@
       int ev;

       ev = socket_count_dec_ssl_desire(nse);
-      update_events(iod, ms, EV_NONE, ev);
+      update_events(iod, ms, nse, EV_NONE, ev);
     }

     rc = SSL_connect(iod->ssl);
@@ -468,11 +468,11 @@
       if (rc == -1 && sslerr == SSL_ERROR_WANT_READ) {
         nse->sslinfo.ssl_desire = sslerr;
         socket_count_read_inc(iod);
-        update_events(iod, ms, EV_READ, EV_NONE);
+        update_events(iod, ms, nse, EV_READ, EV_NONE);
       } else if (rc == -1 && sslerr == SSL_ERROR_WANT_WRITE) {
         nse->sslinfo.ssl_desire = sslerr;
         socket_count_write_inc(iod);
-        update_events(iod, ms, EV_WRITE, EV_NONE);
+        update_events(iod, ms, nse, EV_WRITE, EV_NONE);
       } else if (!(options & SSL_OP_NO_SSLv2)) {
         int saved_ev;

@@ -488,7 +488,7 @@
         close(iod->sd);
         nsock_connect_internal(ms, nse, SOCK_STREAM, iod->lastproto, &iod->peer,
                                iod->peerlen, nsock_iod_get_peerport(iod));
-        nsock_engine_iod_register(ms, iod, saved_ev);
+        nsock_engine_iod_register(ms, iod, nse, saved_ev);

         /* Use SSL_free here because SSL_clear keeps session info, which
          * doesn't work when changing SSL versions (as we're clearly trying to
@@ -501,7 +501,7 @@
         SSL_set_options(iod->ssl, options | SSL_OP_NO_SSLv2);
         socket_count_read_inc(nse->iod);
         socket_count_write_inc(nse->iod);
-        update_events(iod, ms, EV_READ|EV_WRITE, EV_NONE);
+        update_events(iod, ms, nse, EV_READ|EV_WRITE, EV_NONE);
         nse->sslinfo.ssl_desire = SSL_ERROR_WANT_CONNECT;
       } else {
         nsock_log_info("EID %li %s",
@@ -543,10 +543,7 @@
       res = SSL_write(iod->ssl, str, bytesleft);
     else
 #endif
-      if (nse->writeinfo.dest.ss_family == AF_UNSPEC)
-        res = send(nse->iod->sd, str, bytesleft, 0);
-      else
-        res = sendto(nse->iod->sd, str, bytesleft, 0, (struct sockaddr *)&nse->writeinfo.dest, 
(int)nse->writeinfo.destlen);
+      res = ms->engine->io_operations->iod_write(ms, nse->iod->sd, str, bytesleft, 0, (struct sockaddr 
*)&nse->writeinfo.dest, (int)nse->writeinfo.destlen);
     if (res == bytesleft) {
       nse->event_done = 1;
       nse->status = NSE_STATUS_SUCCESS;
@@ -562,14 +559,14 @@

           evclr = socket_count_dec_ssl_desire(nse);
           socket_count_read_inc(iod);
-          update_events(iod, ms, EV_READ, evclr);
+          update_events(iod, ms, nse, EV_READ, evclr);
           nse->sslinfo.ssl_desire = err;
         } else if (err == SSL_ERROR_WANT_WRITE) {
           int evclr;

           evclr = socket_count_dec_ssl_desire(nse);
           socket_count_write_inc(iod);
-          update_events(iod, ms, EV_WRITE, evclr);
+          update_events(iod, ms, nse, EV_WRITE, evclr);
           nse->sslinfo.ssl_desire = err;
         } else {
           /* Unexpected error */
@@ -601,7 +598,7 @@
     else
 #endif
       ev |= socket_count_write_dec(nse->iod);
-    update_events(nse->iod, ms, EV_NONE, ev);
+    update_events(nse->iod, ms, nse, EV_NONE, ev);
   }
 }

@@ -613,7 +610,7 @@

 /* Returns -1 if an error, otherwise the number of newly written bytes */
 static int do_actual_read(struct npool *ms, struct nevent *nse) {
-  char buf[8192];
+  char buf[READ_BUFFER_SZ];
   int buflen = 0;
   struct niod *iod = nse->iod;
   int err = 0;
@@ -627,9 +624,9 @@
     do {
       struct sockaddr_storage peer;
       socklen_t peerlen;
-
       peerlen = sizeof(peer);
-      buflen = recvfrom(iod->sd, buf, sizeof(buf), 0, (struct sockaddr *)&peer, &peerlen);
+
+      buflen = ms->engine->io_operations->iod_read(ms, iod->sd, buf, sizeof(buf), 0, (struct sockaddr *)&peer, 
&peerlen);

       /* Using recv() was failing, at least on UNIX, for non-network sockets
        * (i.e. stdin) in this case, a read() is done - as on ENOTSOCK we may
@@ -712,14 +709,14 @@

         evclr = socket_count_dec_ssl_desire(nse);
         socket_count_read_inc(iod);
-        update_events(iod, ms, EV_READ, evclr);
+        update_events(iod, ms, nse, EV_READ, evclr);
         nse->sslinfo.ssl_desire = err;
       } else if (err == SSL_ERROR_WANT_WRITE) {
         int evclr;

         evclr = socket_count_dec_ssl_desire(nse);
         socket_count_write_inc(iod);
-        update_events(iod, ms, EV_WRITE, evclr);
+        update_events(iod, ms, nse, EV_WRITE, evclr);
         nse->sslinfo.ssl_desire = err;
       } else {
         /* Unexpected error */
@@ -820,7 +817,7 @@
     else
 #endif
       ev |= socket_count_read_dec(nse->iod);
-    update_events(nse->iod, ms, EV_NONE, ev);
+    update_events(nse->iod, ms, nse, EV_NONE, ev);
   }
 }

@@ -861,7 +858,7 @@
     int ev;

     ev = socket_count_readpcap_dec(iod);
-    update_events(iod, ms, EV_NONE, ev);
+    update_events(iod, ms, nse, EV_NONE, ev);
   }
 }

@@ -1266,7 +1263,7 @@
         assert(nse->iod->sd >= 0);
         socket_count_read_inc(nse->iod);
         socket_count_write_inc(nse->iod);
-        update_events(nse->iod, nsp, EV_READ|EV_WRITE|EV_EXCEPT, EV_NONE);
+        update_events(nse->iod, nsp, nse, EV_READ|EV_WRITE|EV_EXCEPT, EV_NONE);
       }
       iod_add_event(nse->iod, nse);
       break;
@@ -1275,7 +1272,7 @@
       if (!nse->event_done) {
         assert(nse->iod->sd >= 0);
         socket_count_read_inc(nse->iod);
-        update_events(nse->iod, nsp, EV_READ, EV_NONE);
+        update_events(nse->iod, nsp, nse, EV_READ, EV_NONE);
 #if HAVE_OPENSSL
         if (nse->iod->ssl)
           nse->sslinfo.ssl_desire = SSL_ERROR_WANT_READ;
@@ -1288,7 +1285,7 @@
       if (!nse->event_done) {
         assert(nse->iod->sd >= 0);
         socket_count_write_inc(nse->iod);
-        update_events(nse->iod, nsp, EV_WRITE, EV_NONE);
+        update_events(nse->iod, nsp, nse, EV_WRITE, EV_NONE);
 #if HAVE_OPENSSL
         if (nse->iod->ssl)
           nse->sslinfo.ssl_desire = SSL_ERROR_WANT_WRITE;
@@ -1309,7 +1306,7 @@
       if (mp->pcap_desc >= 0) { /* pcap descriptor present */
         if (!nse->event_done) {
           socket_count_readpcap_inc(nse->iod);
-          update_events(nse->iod, nsp, EV_READ, EV_NONE);
+          update_events(nse->iod, nsp, nse, EV_READ, EV_NONE);
         }
         nsock_log_debug_all("PCAP NSE #%lu: Adding event to READ_EVENTS", nse->id);


Modified: nmap/nsock/src/nsock_engines.c
==============================================================================
--- nmap/nsock/src/nsock_engines.c      (original)
+++ nmap/nsock/src/nsock_engines.c      Mon Aug 22 12:15:13 2016
@@ -63,6 +63,13 @@

 #include "nsock_internal.h"

+#if HAVE_IOCP
+  extern struct io_engine engine_iocp;
+  #define ENGINE_IOCP &engine_iocp,
+#else
+  #define ENGINE_IOCP
+#endif /* HAVE_IOCP */
+
 #if HAVE_EPOLL
   extern struct io_engine engine_epoll;
   #define ENGINE_EPOLL &engine_epoll,
@@ -94,12 +101,34 @@
   ENGINE_EPOLL
   ENGINE_KQUEUE
   ENGINE_POLL
+  ENGINE_IOCP
   ENGINE_SELECT
   NULL
 };

 static char *engine_hint;

+int posix_iod_connect(struct npool *nsp, int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
+  return connect(sockfd, addr, addrlen);
+}
+
+int posix_iod_read(struct npool *nsp, int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, 
socklen_t *addrlen) {
+  return recvfrom(sockfd, (char *)buf, len, flags, src_addr, addrlen);
+}
+
+int posix_iod_write(struct npool *nsp, int sockfd, const void *buf, size_t len, int flags, const struct sockaddr 
*dest_addr, socklen_t addrlen) {
+  struct sockaddr_storage *dest = (struct sockaddr_storage *)dest_addr;
+  if (dest->ss_family == AF_UNSPEC)
+    return send(sockfd, (char *)buf, len, flags);
+  else
+    return sendto(sockfd, (char *)buf, len, flags, dest_addr, addrlen);
+}
+
+struct io_operations posix_io_operations = {
+  posix_iod_connect,
+  posix_iod_read,
+  posix_iod_write
+};

 struct io_engine *get_io_engine(void) {
   struct io_engine *engine = NULL;
@@ -145,6 +174,9 @@

 const char *nsock_list_engines(void) {
   return
+#if HAVE_IOCP
+  "iocp "
+#endif
 #if HAVE_EPOLL
   "epoll "
 #endif

Modified: nmap/nsock/src/nsock_internal.h
==============================================================================
--- nmap/nsock/src/nsock_internal.h     (original)
+++ nmap/nsock/src/nsock_internal.h     Mon Aug 22 12:15:13 2016
@@ -109,6 +109,7 @@


 /* ------------------- CONSTANTS ------------------- */
+#define READ_BUFFER_SZ 8192

 enum nsock_read_types {
   NSOCK_READLINES,
@@ -360,8 +361,21 @@
    * that other crap */
   unsigned int event_done: 1;
   unsigned int eof: 1;
+
+#if HAVE_IOCP
+  struct extended_overlapped *eov;
+#endif
 };

+struct io_operations {
+  int(*iod_connect)(struct npool *nsp, int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+
+  int(*iod_read)(struct npool *nsp, int sockfd, void *buf, size_t len, int flags,
+    struct sockaddr *src_addr, socklen_t *addrlen);
+
+  int(*iod_write)(struct npool *nsp, int sockfd, const void *buf, size_t len, int flags,
+    const struct sockaddr *dest_addr, socklen_t addrlen);
+};

 struct io_engine {
   /* Human readable identifier for this engine. */
@@ -374,18 +388,21 @@
   void (*destroy)(struct npool *nsp);

   /* Register a new IOD to the engine */
-  int (*iod_register)(struct npool *nsp, struct niod *iod, int ev);
+  int(*iod_register)(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev);

   /* Remove a registered IOD */
-  int (*iod_unregister)(struct npool *nsp, struct niod *iod);
+  int(*iod_unregister)(struct npool *nsp, struct niod *iod);

   /* Modify events for a registered IOD.
    *  - ev_set represent the events to add
    *  - ev_clr represent the events to delete (if set) */
-  int (*iod_modify)(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
+  int (*iod_modify)(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int ev_clr);

   /* Main engine loop */
   int (*loop)(struct npool *nsp, int msec_timeout);
+
+  /* I/O operations */
+  struct io_operations *io_operations;
 };

 /* ----------- NSOCK I/O ENGINE CONVENIENCE WRAPPERS ------------ */
@@ -398,16 +415,16 @@
   return;
 }

-static inline int nsock_engine_iod_register(struct npool *nsp, struct niod *iod, int ev) {
-  return nsp->engine->iod_register(nsp, iod, ev);
+static inline int nsock_engine_iod_register(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev) {
+  return nsp->engine->iod_register(nsp, iod, nse, ev);
 }

 static inline int nsock_engine_iod_unregister(struct npool *nsp, struct niod *iod) {
   return nsp->engine->iod_unregister(nsp, iod);
 }

-static inline int nsock_engine_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
-  return nsp->engine->iod_modify(nsp, iod, ev_set, ev_clr);
+static inline int nsock_engine_iod_modify(struct npool *nsp, struct niod *iod, struct nevent *nse, int ev_set, int 
ev_clr) {
+  return nsp->engine->iod_modify(nsp, iod, nse, ev_set, ev_clr);
 }

 static inline int nsock_engine_loop(struct npool *nsp, int msec_timeout) {

_______________________________________________
Sent through the svn mailing list
https://nmap.org/mailman/listinfo/svn

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: