From owner-freebsd-questions Thu May 22 15:05:00 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id PAA10926 for questions-outgoing; Thu, 22 May 1997 15:05:00 -0700 (PDT) Received: from dori.qlife.org (root@ip-141.hesperia.org [206.129.43.141]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA10919 for ; Thu, 22 May 1997 15:04:53 -0700 (PDT) Received: from cabal95.qlife.org (cabal95.qlife.org [192.168.0.3]) by dori.qlife.org (8.8.5/8.8.5) with SMTP id PAA10542; Thu, 22 May 1997 15:08:14 -0700 Message-ID: <3384C34D.23AD@dal.net> Date: Thu, 22 May 1997 15:06:05 -0700 From: Cabal95 Reply-To: cabal95@dal.net X-Mailer: Mozilla 3.01Gold (Win95; I) MIME-Version: 1.0 To: freebsd-questions@freebsd.org CC: john@starfire.mn.org Subject: Re: bin/3622: gethostbyname fails for file descriptors above 255 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk john@starfire.mn.org wrote: > Number: 3622 > Category: bin > Synopsis: gethostbyname fails for file descriptors above 255 > > Description: > > gethostbyname() fails for a perfectly good domain name once a program > already has file descriptors 0-255 open. I have not yet tracked > this down to find if it is specific to gethostbyname, or if it > may be the underlying infrastructure, or possibly even into the kernel > (in which case the category specified for this report will be wrong). After compiling a debug version of FreeBSD 2.2.1-Release libc.a 3.0 and running your test program below through gdb 4.16, the specific cause of this problem appears to be caused by the following code in /usr/src/lib/libc/net/res_send.c(I'm sorry, line # not available) s = socket(PF_INET, SOCK_DGRAM, 0); ... if (s+1 > FD_SETSIZE) { Perror(stderr, "res_send: too many files"); _res_close(); goto next_ns; } When compiling the libs, FD_SETSIZE on most(all?) systems is 256, defined in /usr/include/sys/types.h. > Fix: One way I fixed this on my system was to recompile libc.a with FD_SETSIZE defined to a higher value. I used 1024 and have not had any of the described problems since doing that. Another way was to go into the /usr/src/lib/libc/net/res_send.c, take out: if (s+1 > FD_SETSIZE) { Perror(stderr, "res_send: too many files"); _res_close(); goto next_ns; } and change: select(s+1, &dsmask, (fd_set *)NULL, (fd_set *)NULL, &timeout) to: select(1, &dsmask, (fd_set *)NULL, (fd_set *)NULL, &timeout) This also works, but there may be problems i'm unaware of, since select() appears to be an internal kernel function, and I don't have the kernel source at this time. Although, from my programming experience on linux, you can call select() with FD's greater than FD_SETSIZE, just not a group of FD's who's total number is greater than FD_SETSIZE. But perhaps this is different under FreeBSD? Cabal95/Daniel