Penguin
Diff: gethostname(2)
EditPageHistoryDiffInfoLikePages

Differences between version 4 and predecessor to the previous major change of gethostname(2).

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 4 Last edited on Monday, December 30, 2002 4:14:49 am by PerryLorier Revert
Older page: version 1 Last edited on Tuesday, June 4, 2002 12:23:41 am by perry Revert
@@ -1,91 +1,50 @@
-GETHOSTNAME  
-!!!GETHOSTNAME  
-NAME  
-SYNOPSIS  
-DESCRIPTION  
-RETURN VALUE  
-ERRORS  
-CONFORMING TO  
-BUGS  
-NOTES  
-SEE ALSO  
-----  
 !!NAME 
  
-  
- gethostname, sethostname - get/set host name 
+gethostname - get host name 
 !!SYNOPSIS 
+ __#include <unistd.h>__  
+ __int gethostname(char *__''name''__, size_t__ ''len''__);__  
  
-  
-__#include __  
-  
-  
-__int gethostname(char *__''name''__, size_t__  
-''len''__);  
-int sethostname(const char *__''name''__, size_t__  
-''len''__);__  
 !!DESCRIPTION 
+These functions are used to access or to change the host name of the current processor. Note, that on the Internet each interface has a at least one address, and names are associated with addresses, so a machine may (and usually does) have multiple names. gethostname(2) will return the one that the machine identifies itself as.  
  
-  
-These functions are used to access or to change the host  
-name of the current processor.  
 !!RETURN VALUE 
+On success, zero is returned. On error, -1 is returned, and ''errno'' is set appropriately.  
  
-  
-On success, zero is returned. On error, -1 is returned, and  
-''errno'' is set appropriately.  
 !!ERRORS 
+;[EINVAL]: ''len'' is negative or, on Linux/i386, ''len'' is smaller than the actual size. (In this last case glibc 2.1 uses [NAMETOOLONG].)  
+;[EFAULT]: ''name'' is an invalid address.  
+;[NAMETOOLONG]: ''len'' is smaller than the length of the hostname  
  
-  
-__EINVAL__  
-  
-  
-''len'' is negative or, for __sethostname__,  
-''len'' is larger than the maximum allowed size, or, for  
-__gethostname__ on Linux/i386, ''len'' is smaller than  
-the actual size. (In this last case glibc 2.1 uses  
-ENAMETOOLONG.)  
-  
-  
-__EPERM__  
-  
-  
-For __sethostname__, the caller was not the  
-superuser.  
-  
-  
-__EFAULT__  
-  
-  
-''name'' is an invalid address.  
 !!CONFORMING TO 
+SVr4, 4.4BSD (this function first appeared in 4.2BSD). POSIX.1 does not define these functions, but ISO/IEC 9945-1:1990 mentions them in B.4.4.1.  
  
-  
-SVr4, 4.4BSD (this function first appeared in 4.2BSD).  
-POSIX.1 does not define these functions, but ISO/IEC  
-9945-1:1990 mentions them in B.4.4.1.  
 !!BUGS 
+According to the SUSv2, gethostname(2) must return ''len'' bytes (a truncated hostname, NUL-terminated or not) when the hostname is longer. Linux/Alpha (which has a system call gethostname(2)) complies with this requirement, but libc and glibc on Linux/i386 only return an error in this case.  
  
-  
-According to the SUSv2, __gethostname__ must return  
-''len'' bytes (a truncated hostname, NUL-terminated or  
-not) when the hostname is longer. Linux/Alpha (which has a  
-system call __gethostname__) complies with this  
-requirement, but libc and glibc on Linux/i386 only return an  
-error in this case.  
 !!NOTES 
+The definition of success varies. SUSv2 defines ''gethostname()'' as `return possibly truncated hostname', and having a small ''len'' does not cause an error return. Of course it must be possible to be certain that one has obtained the full hostname, and to this end  
+SUSv2 guarantees that `Host names are limited to 255 bytes'.  
  
+!!EXAMPLE  
+ #include <unistd.h>  
+ #include <malloc.h>  
+ #include <stdio.h>  
+ #include <string.h>  
  
-The definition of success varies. SUSv2 defines  
-'' gethostname()'' as `return possibly truncated  
-hostname', and having a small ''len'' does not cause an  
-error return. Of course it must be possible to be certain  
-that one has obtained the full hostname , and to this end  
-SUSv2 guarantees that `Host names are limited to 255  
-bytes'.  
-!!SEE ALSO  
+ int main(int argc,char **argv)  
+ {  
+ char domain[[256];  
+ int ret= gethostname(domain,sizeof(domain ));  
+ if (ret==-1) {  
+ perror("gethostname");  
+ return 1;  
+ }  
+ printf("%s\n" ,domain);  
+ free(domain);  
+ return ;  
+ }  
  
  
-getdomainname(2), setdomainname(2),  
- uname(2)  
-----  
+!!SEE ALSO  
+ getdomainname(2), setdomainname(2), uname(2) 
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.