test_gethostname.c revision ab8beedeb70c6941e0ff68014d8db64cee4ef15d
1#include <unistd.h>
2#include <errno.h>
3#include <string.h>
4#include <stdio.h>
5#include <sys/types.h>
6
7int  main( void )
8{
9    char  hostname[512];
10    int   ret;
11
12    ret = gethostname(hostname, sizeof(hostname));
13    if (ret < 0) {
14        printf("gethostname() returned error %d: %s\n", errno, strerror(errno));
15        return 1;
16    }
17
18    printf("gethostname() returned '%s'\n", hostname);
19    return 0;
20}
21