This ain't fully tried and tested, but it's a start.
Code:
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void)
{
/* Get the local hostname */
char sHostName[80];
int nRet;
nRet = gethostname(sHostName, sizeof(sHostName));
if (nRet == 0)
{
struct hostent* pHostEnt;
/* Resolve hostname for local address */
if ((pHostEnt = gethostbyname(sHostName)) == NULL)
{
perror("gethostbyname");
return(1);
}
printf("%s:%s", pHostEnt->h_name, inet_ntoa(*((struct in_addr *)pHostEnt->h_addr)));
}
}