Récupérer l'ip Lan de la machine
Bonjour,
je n'arrive pas a recuperer l'ip sur le reseau de ma machine, j'ai bien essayé avec getshostname/gethostbyname mais je recupere l'addresse "127.0.1.1" mais ce que je recherche a obtenir c'est l'addresse qui apparait lorsque je fais un ifconfig sur mon eth0 ("172.16.0.17"), comment faire ?
voici ce que j'ai fais jusqu'ici :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| char *hostName;
hostName = malloc(sizeof(HOST_NAME_MAX));
gethostname(hostName, HOST_NAME_MAX);
struct hostent *pHost;
pHost = gethostbyname(hostName);
if (!pHost)
{
perror("gethostbyname");
exit (-1);
}
int i;
for (i = 0; pHost->h_addr_list[i] != 0; ++i)
{
struct in_addr addr;
memcpy(&addr, pHost->h_addr_list[i], sizeof(struct in_addr));
printf("%s\n", inet_ntoa(addr));
} |