From owner-freebsd-audit Wed Mar 7 8:26:54 2001 Delivered-To: freebsd-audit@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id B8E9037B718; Wed, 7 Mar 2001 08:26:41 -0800 (PST) (envelope-from ru@whale.sunbay.crimea.ua) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.2/8.11.2) id f27GOrS95934; Wed, 7 Mar 2001 18:24:53 +0200 (EET) (envelope-from ru) Date: Wed, 7 Mar 2001 18:24:53 +0200 From: Ruslan Ermilov To: Max Khon Cc: freebsd-audit@FreeBSD.ORG, Garrett Wollman Subject: Re: MAXHOSTNAMELEN Message-ID: <20010307182453.D36537@sunbay.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from fjoe@iclub.nsu.ru on Wed, Mar 07, 2001 at 09:54:26PM +0600 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 : 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