Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. /*
  2.  * gethostbyname.c - Example of using gethostbyname(3)
  3.  * Martin Vidner <mvidner@suse.cz>
  4.  */
  5. #include<strings.h>
  6. #include <stdio.h>
  7. #include <netdb.h>
  8. #include <netinet/in.h>
  9.  
  10. struct hostent *he;
  11. struct in_addr a;
  12.  
  13. int main (int argc, char **argv)
  14. {
  15.     if (argc != 2)
  16.     {
  17.         fprintf(stderr, "usage: %s hostname\n", argv[0]);
  18.         return 1;
  19.     }
  20.     he = gethostbyname (argv[1]);
  21.     if (he)
  22.     {
  23.         printf("name: %s\n", he->h_name);
  24.         while (*he->h_aliases)
  25.             printf("alias: %s\n", *he->h_aliases++);
  26.         while (*he->h_addr_list)
  27.         {
  28.             bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
  29.             printf("address: %s\n", inet_ntoa(a));
  30.         }
  31.     }
  32.     else
  33.         herror(argv[0]);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement