#include <stdio.h>#include <netdb.h>int main() { char hostname[255]; // fetch the hostname // the problem here is that the hostname could be accociated with 127.0.0.1 only // it seems there is no way to query the other IPs int ret = gethostname(hostname, sizeof(hostname)); printf("Hostname: %s\n", hostname); struct hostent* host = gethostbyname(hostname); int i = 0; while(host->h_addr_list[i] != NULL) { printf("Address[%d]: %s\n", i, inet_ntoa(*((struct in_addr *)host->h_addr_list[i]))); ++i; } return 0;}