From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot) Newsgroups: comp.os.msdos.djgpp Subject: Re: How should gethostname() work? Date: Tue, 31 Mar 1998 00:31:22 GMT Organization: [posted via] Easynet UK Lines: 42 Message-ID: <352022b1.5037141@news.easynet.co.uk> References: <6fat7h$2jh$1 AT news-hrz DOT uni-duisburg DOT de> NNTP-Posting-Host: foot.easynet.co.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Wed, 25 Mar 1998 13:27:32 +0100, michael DOT mauch AT gmx DOT de (Michael Mauch) wrote: >Also, I see that gethostname() retrieves only up to 16 characters of the >host name. Shouldn't that be MAXGETHOSTNAME (==128)? The docs would still be correct, provided 16 < MAXGETHOSTNAME. >*** gethostn.c0 Tue Jun 13 08:58:54 1995 >--- gethostn.c Wed Mar 25 11:01:06 1998 ... >*************** >*** 36,41 **** >--- 37,45 ---- > } > > len = strlen (h); >+ for (p = h + len - 1; p>=h; p--) >+ if (' ' == *p) >+ *p = '\0', len--; > if (len + 1 > size) > { > errno = ERANGE; Your calculation of `len' is not watertight here; you're effectively truncating the string at the first space, but `len' will be inaccurate if the spaces are not all in a block at the end of the string. For example, if `h' points to "Hello world", you'll get a length of 10 and a string: "Hello\0world", which will seem to be of length 5. Also, if `h' comes from getenv you should not alter the string. strcpy it first, then fiddle with it. Finally, note that `dosbuf' is only used when getting the hostname from DOS networking systems. Perhaps the return string from the interrupt is only allowed to be 16 characters long (I'm not sure) -- in which case there's not much point in making `dosbuf' MAXHOSTNAME bytes long. -- george DOT foot AT merton DOT ox DOT ac DOT uk