Some domain’s serve under multiple ip addresses for example google.com

if you want to query this ip addresses then you can use this code block

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
 if (argc < 2) {
   fprintf(stderr,"Usage: ./app www.google.com\n");
   exit(1);
 }

 struct hostent *hp = gethostbyname(argv[1]);

 if (hp == NULL) {
   fprintf(stderr,"query failed\n");
   exit(1);
 } else {
   unsigned int i=0;
   while ( hp -> h_addr_list[i] != NULL) {
     printf( "%d -> %s ",i, inet_ntoa( *( struct in_addr*)( hp -> h_addr_list[i])));
     i++;
   }
   exit(0);
 }
}


Buy me a beer

Related posts:

  1. how to assign multiple ip address on one ethernet (For linux) Assign new ip =   ifconfig eth0 192.168.1.10 Assign IP/Subnet...
  2. How to find active local computers on a LAN with Linux machine This entry gives a way to find active computers on...
  3. Sample Linux Driver (module) I am generally writing linux drivers for embedded systems for...
  4. Linux Shared Lib Creation, Compilation & Usage Shared library file b.c #include void b_printer () { printf...
  5. Linux i2c driver implementation An I2C chip driver controls the process of talking to...