Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /*
  2. * resolve.c
  3. *
  4. * Copyleft (C) 2015 Sun Dro (a.k.a. kala13x)
  5. *
  6. * Simple app to resolve addres.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdint.h>
  12. #include <unistd.h>
  13. #include <netdb.h>
  14. #include <arpa/inet.h>
  15.  
  16. uint32_t GetInetAddr(const char *pAddr)
  17. {
  18. struct hostent *pServer = gethostbyname(pAddr);
  19. if (pServer == NULL)
  20. {
  21. printf("Error: No such host: %s\n", pAddr);
  22. return 0;
  23. }
  24.  
  25. const char *pIpAddr = inet_ntoa(*(struct in_addr *)pServer->h_addr);
  26. printf("Resoled IP Addr: %s\n", pIpAddr);
  27.  
  28. return (uint32_t)inet_addr(pIpAddr);
  29. }
  30.  
  31. int main(int argc, char *argv[])
  32. {
  33. if (argc < 2)
  34. {
  35. printf("Usage: %s <domain>\n", argv[0]);
  36. printf("Example: %s google.ge\n", argv[0]);
  37. return 1;
  38. }
  39.  
  40. uint32_t nAddr = GetInetAddr(argv[1]);
  41. if (nAddr) printf("Inet Byte Addr: %llu\n", nAddr);
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement