I wish to get the system IP address in my C program. Unfortunately, when I tried the following code, I kept getting and not the actual IP address of my system.

struct sockaddr_in server_addr;
struct hostent *host;
char hostname[256];

gethostname(hostname, sizeof(hostname));
host = gethostbyname(hostname);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(5000);
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
printf("IP address: %s\n", inet_ntoa(server_addr.sin_addr));