From owner-freebsd-current Tue Nov 14 10:06:01 1995 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id KAA27796 for current-outgoing; Tue, 14 Nov 1995 10:06:01 -0800 Received: from halloran-eldar.lcs.mit.edu (halloran-eldar.lcs.mit.edu [18.26.0.159]) by freefall.freebsd.org (8.6.12/8.6.6) with SMTP id KAA27781 for ; Tue, 14 Nov 1995 10:05:52 -0800 Received: by halloran-eldar.lcs.mit.edu; (5.65/1.1.8.2/19Aug95-0530PM) id AA23801; Tue, 14 Nov 1995 13:05:45 -0500 Date: Tue, 14 Nov 1995 13:05:45 -0500 From: "Garrett A. Wollman" Message-Id: <9511141805.AA23801@halloran-eldar.lcs.mit.edu> To: "Garrett A. Wollman" Cc: current@freebsd.org Subject: Re: cvs commit: src/sys/kern kern_sysctl.c In-Reply-To: <9511141616.AA23508@halloran-eldar.lcs.mit.edu> References: <570.816343308@critter.tfs.com> <9511141616.AA23508@halloran-eldar.lcs.mit.edu> Sender: owner-current@freebsd.org Precedence: bulk <> Well, what if the hostname actually WAS 255 bytes long then ? > Then you return an error. I then later quoted: > FreeBSD 2.2: > Gethostname() returns the standard host name for the current processor, > as previously set by sethostname(). The parameter namelen specifies the > size of the name array. The returned name is null-terminated unless in- > sufficient space is provided. This quotation is what you should do, rather than returning an error. This may require that gethostname() do a little more work than it does now. For example: long /* XXX ??? */ gethostname(char *name, int namelen) { char buf[MAXHOSTNAMELEN]; int mib[2]; size_t size; mib[0] = CTL_KERN; mib[1] = KERN_HOSTNAME; size = sizeof buf; if (sysctl(mib, 2, name, &size, (void *)0, (size_t)0) < 0) return -1; strncpy(name, buf, namelen < (sizeof buf) ? namelen : sizeof buf); return 0; } -GAWollman -- Garrett A. Wollman | Shashish is simple, it's discreet, it's brief. ... wollman@lcs.mit.edu | Shashish is the bonding of hearts in spite of distance. Opinions not those of| It is a bond more powerful than absence. We like people MIT, LCS, ANA, or NSA| who like Shashish. - Claude McKenzie + Florent Vollant