Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. int getIpFromHostname(){
  2.  
  3. struct hostent *he;
  4. struct in_addr **addr_list;
  5.  
  6. if ((he = gethostbyname(INTERNET_HOSTNAME)) == NULL) { // get the host info
  7. herror("gethostbyname");
  8. return 2;
  9. }
  10.  
  11. // print information about this host:
  12. printf("Official name is: %s\n", he->h_name);
  13. printf(" IP addresses: ");
  14. addr_list = (struct in_addr **)he->h_addr_list;
  15. for(int i = 0; addr_list[i] != NULL; i++) {
  16. printf("%s ", inet_ntoa(*addr_list[i]));
  17. }
  18. printf("\n");
  19.  
  20. return 0;
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement