Nmap Development mailing list archives

[RFC] Fix for non-socket select()s: fselect()


From: "Kris Katterjohn" <katterjohn () gmail com>
Date: Tue, 9 Sep 2008 08:06:03 +0530

Hey everyone,

I've forced myself to stay in Windows long enough to where I think I
managed to get a good work-around for non-socket select()s! [1]

I've created an fselect() function in nbase which has special case
code for select() calls with the read set including stdin.  This new
function will be called by Nsock and Ncat to hopefully get them
working well on Windows.

Ncat will call fselect() itself in server-mode, and use it through
Nsock in client-mode.

The function examines and messes with the fd_sets, and decides whether
or not to just simply call select() and return.  If stdin is going to
be watched, it loops with a select() call with a 250ms timeout, and
then checks stdin the best ways I could figure out (depending on
whether or not stdin is the console or not).  My original Ncat code
had a 1s timeout, but this was because I thought I could find a
different way around the problem and just wanted to implement a
temporary fix.  Talking with Fyodor the other day, he suggested a
250ms timeout per call if I was going to continue with this method.

I've attached a patch against Nbase and Nsock, and here's the gist of it:

* nbase/nbase_misc.c contains the new fselect() function

* The Nsock nsi_new2() function, which is used by Ncat to have Nsock
take over control to stdin, now handles stdin specially.  This is the
only "problem" I have with my solution.  Instead of dup'ing the
descriptor like the function normally does, it leaves stdin alone and
keeps it.  Of course, I don't see this as a problem because the
benefits of this simple patch outway the special-casing of an already
special case scenario of having Nsock handle stdin.  Nsock is just
broken in this case on Windows without this anyway.

I've been testing a patched Ncat with these changes and it all seems
to work great in client- and server-mode with stdin being the console,
or a redirected file.

So, if there are no objections, I'll commit this (and the Ncat changes) soon.

Thanks,
Kris Katterjohn

[1] http://seclists.org/nmap-dev/2008/q3/0249.html

Attachment: fselect.patch
Description:


_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: