1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Moved function max_sd() to libnetutil. Also, two new helper functions have been added.

This commit is contained in:
luis
2010-10-20 15:57:50 +00:00
parent 00e4f1637d
commit d0a4d0ad50
4 changed files with 101 additions and 47 deletions

View File

@@ -108,10 +108,6 @@
#include <sys/time.h>
#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#if HAVE_UNISTD_H
/* #include <sys/unistd.h> */
#include <unistd.h>
@@ -1665,45 +1661,6 @@ void max_rcvbuf(int sd) {
#endif /* WIN32 */
}
/* Maximize the open file descriptor limit for this process go up to the
max allowed */
int max_sd() {
#ifndef WIN32
struct rlimit r;
static int maxfds = -1;
if (maxfds > 0)
return maxfds;
#if(defined(RLIMIT_NOFILE))
if (!getrlimit(RLIMIT_NOFILE, &r)) {
r.rlim_cur = r.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &r))
if (o.debugging)
perror("setrlimit RLIMIT_NOFILE failed");
if (!getrlimit(RLIMIT_NOFILE, &r)) {
maxfds = r.rlim_cur;
return maxfds;
} else
return 0;
}
#endif
#if(defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE))
if (!getrlimit(RLIMIT_OFILE, &r)) {
r.rlim_cur = r.rlim_max;
if (setrlimit(RLIMIT_OFILE, &r))
if (o.debugging)
perror("setrlimit RLIMIT_OFILE failed");
if (!getrlimit(RLIMIT_OFILE, &r)) {
maxfds = r.rlim_cur;
return maxfds;
} else
return 0;
}
#endif
#endif /* WIN32 */
return 0;
}
/* Give broadcast permission to a socket */
void broadcast_socket(int sd) {