exercice(list des adrasse IP)

exercice(list des adrasse IP)

par kada ahlem,
Nombre de réponses : 1

#include <stdio.h>


#include <unistd.h>


#include <arpa/inet.h>


#include <sys/socket.h>


#include <netinet/in.h>


#include <netdb.h>


int main(int argc,char **argv)   {


int i;

struct hostent *he;

struct in_addr **addr_list;

struct in_addr addr;

he = gethostbyname(argv[1]);   //reçoit un URI comme un arg

if (he == NULL) { // Effectue une vérification des erreurs

    perror("gethostbyname"); 

     return -1;


}// Affiche les informations sur cet hôte 

printf("Official name is: %s\n", he->h_name);


printf("IP address: %s\n", inet_ntoa(*(struct in_addr*)he->h_addr));


printf("All addresses: ");


addr_list = (struct in_addr **)he->h_addr_list;


for(i = 0; addr_list[i] != NULL; i++) {

   printf("%s ", inet_ntoa(*addr_list[i]));

}

return 0;

execution

code