Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement