代码
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <arpa/inet.h>
int main( int argc, char* argv[] ){
struct hostent* host;
if( argc < 2 ){
printf( "Usage : %s <hostname> \n", argv[0] );
exit(EXIT_FAILURE);
}
host = gethostbyname( argv[1] );
int idx = 0;
while( host->h_addr_list[idx] ){
printf( "IP address %d %s\n", idx+1, inet_ntoa( *(struct in_addr*)host->h_addr_list[idx]) );
idx++;
}
exit(EXIT_SUCCESS);
}
/*
IP address 1 61.135.169.125
IP address 2 61.135.169.121
*/