Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

gethostname() - get the name of the current host

&pagelevel(4)&pagelevel

#include <unistd.h>

int gethostname(char *name, size_t namelen);

Description

The gethostname() function returns the socket host name for the current host in the name parameter. The length of the name string variable must be specified in the namelen parameter when gethostname() is called.

If the length of the name string variable specified by namelen suffices for storing the host name, the host name is terminated with a null byte. Otherwise, the excess socket 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 set to indicate the error.