/*-------------------------------------------------------------------------- Copyright 1999,2000, Dan Kegel http://www.kegel.com/ See the file COPYING This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- Program to measure limits on network sockets, file descriptors, etc. --------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef AF_LOCAL #define AF_LOCAL AF_UNIX #endif #define MAX_TEST 100000 int fds[MAX_TEST]; static int count_fds(int want) { int i; int nfds; for (i=0; i MAX_TEST) { printf("Sorry, want must be between 1 and %d\n", MAX_TEST); exit(1); } if (argc < 3) ipadrstr = "127.0.0.1"; else ipadrstr = argv[2]; ipadr = inet_addr(ipadrstr); if (ipadr == -1) { printf("Bad ip address %s.\n", ipadrstr); exit(1); } if (argc < 4) portnum = 80; else { const char *portnumstr; portnumstr = argv[3]; portnum = atoi(portnumstr); if ((portnum <= 0) || (portnum > 65535)) { printf("Bad port number '%s'. Must be number between 1 and 65535.\n", portnumstr); exit(1); } } #ifdef LINUX /* Linux-specific system tuning data */ printf("/proc/sys/net/ipv4/ip_local_port_range is: "); fflush(stdout); system("cat /proc/sys/net/ipv4/ip_local_port_range"); printf("/proc/sys/fs/file-nr is: "); fflush(stdout); system("cat /proc/sys/fs/file-nr"); printf("/proc/sys/fs/file-max is: "); fflush(stdout); system("cat /proc/sys/fs/file-max"); printf("/proc/sys/fs/inode-nr is: "); fflush(stdout); system("cat /proc/sys/fs/inode-nr"); printf("/proc/sys/fs/inode-max is: "); fflush(stdout); system("cat /proc/sys/fs/inode-max"); #endif printf("Can open %d AF_LOCAL sockets with socketpair\n", count_socketpairs(AF_LOCAL, want)); printf("Can open %d AF_INET sockets with socketpair\n", count_socketpairs(AF_INET, want)); printf("Can open %d fds\n", count_fds(want)); printf("Can open %d files\n", count_files(want)); printf("Can poll %d sockets\n", count_poll(want)); printf("Can bind %d ephemeral ports\n", count_sockets(want)); //sleep(3); //printf("Can start %d nonblocking connect()'s\n", count_connects(ipadr, portnum, want)); return 0; }