#include #include #include #include int main(int argc, char **argv) { char hostname[PATH_MAX]; hostname[sizeof(hostname) - 1] = '\0'; if (gethostname(hostname, sizeof(hostname) - 1) == 0) { printf("gethostname done\n"); struct hostent *h = gethostbyname(hostname); printf("gethostbyname done\n"); if (h) printf("h: '%s'\n", h->h_name); else printf("!h: '%s'\n", hostname); } else { printf("gethostname error\n"); } return 0; }