danielhilst

Reverse resolve

Jun 27th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/socket.h>
  5. #include <netdb.h>
  6.  
  7. static char name[32];
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.         int error;
  12.         char *ip = argv[1];
  13.  
  14.         struct sockaddr_in sa;
  15.        
  16.         if (argc <= 1) {
  17.                 fprintf(stderr, "usage: %s <ip address>\n", argv[0]);
  18.                 exit(EXIT_FAILURE);
  19.         }
  20.  
  21.         memset(&sa, 0, sizeof(sa));
  22.         sa.sin_family = AF_INET;
  23.         error = inet_aton(ip, &sa.sin_addr);
  24.         if (error == 0) {
  25.                 perror("inet_aton()");
  26.                 exit(EXIT_FAILURE);
  27.         }
  28.  
  29.         error = getnameinfo((struct sockaddr *)&sa, sizeof(sa), name, sizeof(name), NULL, 0, NI_NAMEREQD);
  30.         if (error) {
  31.                 perror("getnameinfo()");
  32.                 exit(EXIT_FAILURE);
  33.         }
  34.         puts(name);
  35.         return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment