test_gethostname.c revision e16cb84e2324f05334d18dcf5956f20f44262b62
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