gethostname |
Prototype: |
#include <unistd.h>
int gethostname(char *name, size_t len);
|
General Description: |
Gets the local-host's name. The call places the result in the name parameter up to len-bytes. |
Return Value: |
Zero (0) if everything goes well. If an error occurs, you can find the cause in errno. |
Parameters |
name |
The buffer to accept the name of the local host. |
len |
The number of bytes available in name. |
Possible Errors |
EINVAL |
len is negative, or, for gethostname() on Linux/i386, len is smaller than the actual size. |
EFAULT |
name is an invalid address. |
Examples |
char name[50];
if ( gethostname(name, sizeof(name)) != 0 )
perror("gethostname() failed");
printf("My host is: %s\n", name);
|