gethostname

Returns the official hostname for the current machine.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <netdb.h> 
   
  int gethostname (
     char  *name,
     int    namelen);
  

Parameters

name

(OUT) Points to a null-terminated string containing the official name of the host.

namelen

(IN) Specifies the size of the array pointed to by name.

Return Values

If successful, returns 0. Otherwise, returns -1.

Remarks

The gethostname function returns the standard hostname for the current host machine. The namelen parameter specifies the size of the array pointed to by name. The returned name is null terminated, unless insufficient space is provided.

See Also