Date: Tue, 14 Nov 1995 13:05:45 -0500 From: "Garrett A. Wollman" <wollman@lcs.mit.edu> To: "Garrett A. Wollman" <wollman@lcs.mit.edu> Cc: current@freebsd.org Subject: Re: cvs commit: src/sys/kern kern_sysctl.c Message-ID: <9511141805.AA23801@halloran-eldar.lcs.mit.edu> In-Reply-To: <9511141616.AA23508@halloran-eldar.lcs.mit.edu> References: <Pine.BSF.3.91.951114041815.243B-100000@jhome.DIALix.COM> <570.816343308@critter.tfs.com> <9511141616.AA23508@halloran-eldar.lcs.mit.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
<<On Tue, 14 Nov 1995 11:16:03 -0500, I said something inconsistent: >> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9511141805.AA23801>