SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <netdb.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char ** argv) {
  6.   if (argc < 2) {
  7.     printf("Usage: %s hostname", argv[0]);
  8.     exit(-1);
  9.   }
  10.  
  11.   struct hostent * hp = gethostbyname(argv[1]);
  12.  
  13.   if (hp == NULL) {
  14.     printf("gethostbyname() failed\n");
  15.   } else {
  16.     printf("%s = ", hp - > h_name);
  17.     unsigned int i = 0;
  18.     while (hp - > h_addr_list[i] != NULL) {
  19.       printf("%s ", inet_ntoa( * (struct in_addr * )(hp - > h_addr_list[i])));
  20.       i++;
  21.     }
  22.     printf("\n");
  23.   }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top