Back to index

nagios-plugins  1.4.16
Functions
gethostname.c File Reference
#include <config.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>

Go to the source code of this file.

Functions

int gethostname (char *name, size_t len)

Function Documentation

int gethostname ( char *  name,
size_t  len 
)

Definition at line 43 of file gethostname.c.

{
#ifdef HAVE_UNAME
  struct utsname uts;

  if (uname (&uts) == -1)
    return -1;
  if (len > sizeof (uts.nodename))
    {
      /* More space than we need is available.  */
      name[sizeof (uts.nodename)] = '\0';
      len = sizeof (uts.nodename);
    }
  strncpy (name, uts.nodename, len);
#else
  strcpy (name, "");            /* Hardcode your system name if you want.  */
#endif
  return 0;
}

Here is the caller graph for this function: