1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-01 12:29:03 +00:00

add some FD_SETSIZE research from David

This commit is contained in:
fyodor
2009-08-22 21:34:16 +00:00
parent 08073b43b8
commit 4d04d37ab5

View File

@@ -196,6 +196,46 @@ o [Web] Consider adding training/introduction videos to the Nmap site
o Change Nsock to give an error if you try to FD_SET a fd larger than
FD_SETSIZE. [Brandon]
o Some research from David:
We have help off on this change because of Windows portability
problems. The Windows fd_set works differently than the Unix
fd_set. In Unix, FD_SETSIZE (which is typically 1024) is both the
maximum number of file descriptors that can be in the set and one
greater than the greatest file descriptor number that can be
set. In other words, we want to bail out whenever someone tries
to FD_SET file descriptor 1060, for example. But on Windows it's
different: FD_SETSIZE is only 64, but any file descriptor
numbers, no matter how great, may be stored in the set. Windows
socket descriptors are typically greater than 1023, but you can
only have 64 of them in the set at once.
So the fix on Unix would be
--- nsock/src/nsock_core.c (revision 15214)
+++ nsock/src/nsock_core.c (working copy)
@@ -97,6 +97,7 @@
do { \
assert((count) >= 0); \
(count)++; \
+ assert((sd) < FD_SETSIZE); \
FD_SET((sd), (fdset)); \
(max_sd) = MAX((max_sd), (sd)); \
return 1; \
@@ -107,6 +108,7 @@
assert((count) > 0); \
(count)--; \
if ((count) == 0) { \
+ assert((sd) < FD_SETSIZE); \
FD_CLR((sd), (fdset)); \
assert((iod)->events_pending > 0); \
if ((iod)->events_pending == 1 && (max_sd) == (sd)) \
But that doesn't work on Windows (I just tried it) because even
the smallest socket descriptor is bigger than FD_SETSIZE, 64.
Really we're trying to accomplish two different things on the two
platforms: On Unix we must not store a file descriptor greater
than 1023, no matter how many or how few other descriptors have
been set. On Windows we must not set more than 64 descriptors at
a time, no matter what their descriptor number happens to be.
o Change Nsock so that it is able to take advantage of more modern
interfaces to dealing with large sockets, rather than just select.