diff options
| -rw-r--r-- | man2/gethostname.2 | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/man2/gethostname.2 b/man2/gethostname.2 index 1130db655b..ab082b1650 100644 --- a/man2/gethostname.2 +++ b/man2/gethostname.2 @@ -38,11 +38,11 @@ gethostname, sethostname \- get/set host name .br .BI "int sethostname(const char *" name ", size_t " len ); .SH DESCRIPTION -These functions are used to access or to change the host name of the +These system calls are used to access or to change the host name of the current processor. The .BR gethostname () -function returns a NUL-terminated hostname (set earlier by +system call returns a NUL-terminated hostname (set earlier by .BR sethostname ()) in the array \fIname\fP that has a length of \fIlen\fP bytes. In case the NUL-terminated hostname does not fit, no error is @@ -78,19 +78,46 @@ the caller did not have the .B CAP_SYS_ADMIN capability. .SH "CONFORMING TO" -SVr4, 4.4BSD (this function first appeared in 4.2BSD). +SVr4, 4.4BSD (this interfaces first appeared in 4.2BSD). POSIX 1003.1-2001 specifies .BR gethostname () but not .BR sethostname (). -.SH BUGS -For many Linux kernel / libc combinations -.BR gethostname () -will return an error instead of returning a truncated hostname. .SH NOTES SUSv2 guarantees that `Host names are limited to 255 bytes'. POSIX 1003.1-2001 guarantees that `Host names (not including the terminating NUL) are limited to HOST_NAME_MAX bytes'. +.SH "GLIBC NOTES" +The GNU C library implements +.BR gethostname () +as a library function that calls calls +.BR uname (2) +and copies up to +.I len +bytes from the returned +.I nodename +field into +.IR name . +Having performed the copy, the function then checks if the length of the +.I nodename +was greater than or equal to +.IR len , +and if it is, then the function returns \-1 with +.I errno +set to +.BR ENAMETOOLONG . +Versions of glibc before 2.2 +.\" At least glibc 2.0 and 2.1, older versions not checked +handle the case where the length of the +.I nodename +was greater than or equal to +.IR len +differently: nothing is copied into +.I name +and the function returns \-1 with +.I errno +set to +.BR ENAMETOOLONG . .SH "SEE ALSO" .BR getdomainname (2), .BR setdomainname (2), |
