#include <sys.socket.h>
Kernighan-Ritchie-C:
int gethostname(name, namelen);
char *name;
int namelen;
ANSI-C:
int gethostname(char* name, int namelen);
Description
Use of the gethostname() function only makes sense in the AF_INET and AF_INET6 address families.
The gethostname() function returns the socket host name in the name parameter. Socket host names are unique network-wide and are assigned in TCP/IP networks to all hosts that can be reached via a TCP/IP route
(see the “BCAM Volume 1/2” manual for details).
The length of the name string variable must be specified in the namelen parameter in the gethostname() call.
If the length of the name string variable specified by namelen is sufficient to accept the host name, the host name is terminated with a null byte. Otherwise, the excess host name characters are truncated, and it is then undefined whether the host name returned in this way is terminated by a null byte.
Return value
0:
If successful.
-1:
If errors occur. errno is not set.