Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Mar 2001 18:24:53 +0200
From:      Ruslan Ermilov <ru@FreeBSD.ORG>
To:        Max Khon <fjoe@iclub.nsu.ru>
Cc:        freebsd-audit@FreeBSD.ORG, Garrett Wollman <wollman@FreeBSD.ORG>
Subject:   Re: MAXHOSTNAMELEN
Message-ID:  <20010307182453.D36537@sunbay.com>
In-Reply-To: <Pine.BSF.4.21.0103072153170.43511-100000@iclub.nsu.ru>; from fjoe@iclub.nsu.ru on Wed, Mar 07, 2001 at 09:54:26PM %2B0600
References:  <Pine.BSF.4.21.0103072153170.43511-100000@iclub.nsu.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Mar 07, 2001 at 09:54:26PM +0600, Max Khon wrote:
> hi, there!
> 
> should one allocate buffer of size MAXHOSTNAMELEN or MAXHOSTNAMELEN+1
> bytes when using gethostname?
> 
> lark:/usr/include$grep -Ir MAXHOSTNAMELEN .
> ./nfs/nfsdiskless.h:    char            my_hostnam[MAXHOSTNAMELEN]; /*
> Client host name */
> ./nfs/nfsdiskless.h:    char            my_hostnam[MAXHOSTNAMELEN]; /*
> Client host name */
> ./protocols/timed.h:    char tsp_name[MAXHOSTNAMELEN];
> ./sys/kernel.h:extern char hostname[MAXHOSTNAMELEN];
> ./sys/kernel.h:extern char domainname[MAXHOSTNAMELEN];
> ./sys/param.h:#define MAXHOSTNAMELEN    256             /* max hostname
> size */
> ./sys/jail.h:   char            pr_host[MAXHOSTNAMELEN];
> ./fetch.h:    char       host[MAXHOSTNAMELEN+1];
> lark:/usr/include$
> 
Current POSIX draft says:

: NAME
:           gethostname - get name of current host
: SYNOPSIS
:           #include <unistd.h>
:           int gethostname(char *name, socklen_t namelen);
: DESCRIPTION
:           The gethostname() function shall return the standard host name
:           for the current machine.  The namelen argument shall specify
:           the size of the array pointed to by the name argument.  The
:           returned name shall be null-terminated, except that if namelen
:           is an insufficient length to hold the host name, then the
:           returned name shall be truncated and it is unspecified whether
:           the returned name is null-terminated.
:           Host names are limited to 255 bytes.
: RETURN VALUE
:           Upon successful completion, 0 shall be returned; otherwise,
:           -1 shall be returned.

And given that MAXHOSTNAMELEN is defined as 256, it would appear that
passing MAXHOSTNAMELEN would be enough.  But we are not currently
POSIX-compatible; kern_mib.c defines ``char hostname[MAXHOSTNAMELEN]''
thus allowing host names of up to 256 bytes, so (in FreeBSD), you
should pass MAXHOSTNAMELEN+1.

This could be fixed by redefining MAXHOSTNAMELEN to 255.  Garrett?


Cheers,
-- 
Ruslan Ermilov		Oracle Developer/DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010307182453.D36537>