Opened 18 years ago
Closed 17 years ago
#1250 closed bug (fixed)
hostname not fully implemented
Reported by: | jonas.kirilla | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | System/libroot.so | Version: | R1/pre-alpha1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
Shell command 'hostname' returns 'beast'. Shell command 'uname --nodename' returns 'unknown'.
Both are hardcoded values. /etc/hostname is ignored.
Setting a hostname using 'hostname foo' does not work.
Implementation ideas:
src/system/libroot/posix/sys/uname.c
- call gethostname(), copy this to utsname->nodename
src/system/libroot/posix/unistd/hostname.c
- implement reading of /etc/hostname if present, in gethostname()
- implement writing of /etc/hostname, in sethostname()
The supplied patch makes uname.c consult gethostname() so both shell commands agree that (for now) the name of the host is 'beast'.
I will try to also make a patch for hostname.c.
Attachments (1)
Change History (4)
by , 18 years ago
Attachment: | uname.c.diff added |
---|
comment:1 by , 18 years ago
comment:2 by , 18 years ago
FWIW, in glibc gethostname() is implemented with a call to uname(), the other way around from what my patch does.
http://www.gnu.org/software/libc/manual/html_node/Platform-Type.html#Platform-Type
comment:3 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks for your work! It's fixed in hrev22492.
Utsname.nodename is limited by _SYS_NAMELEN to 32 bytes, whereas MAXHOSTNAMELEN is defined as 256 in sys/param.h. Calling gethostname() with a too short string would of course truncate it. I don't know if this truncation of the hostname is a problem for uname or not.
FreeBSD appears to use a 32 bytes field length for utsname in the kernel, and 256 when in user space. http://fxr.watson.org/fxr/source/sys/utsname.h?v=RELENG62
http://www.opengroup.org/onlinepubs/009695399/functions/gethostname.html
The FreeBSD man page on GETHOSTNAME(3) has this to say:
STANDARDS The gethostname() function conforms to IEEE Std 1003.1-2001 (
POSIX.1). Callers should be aware that {HOST_NAME_MAX} may be variable or infinite, but is guaranteed to be no less than {_POSIX_HOST_NAME_MAX}. On older systems, this limit was defined in the non-standard header <sys/param.h> as MAXHOSTNAMELEN, and counted the terminating null. The sethostname() function and the error returns for gethostname() are not standardized.
So far I haven't figured out whether HOST_NAME_MAX is used in Linux. I've only found a lot of MAXHOSTNAMELEN in the sources.