Mail Archives: djgpp/1998/03/30/19:45:48
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
- Raw text -