Guest User

Untitled

a guest
Dec 27th, 2010
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. /* gcc -W -Wall -o test test.c && valgrind --leak-check=full --show-reachable=yes ./test
  2.  */
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <sys/param.h>
  9. #include <netdb.h>
  10.  
  11. int main(int argc, char **argv)
  12. {
  13.   (void)argc;
  14.   (void)argv;
  15.  
  16.   char hostname[MAXHOSTNAMELEN+1];
  17.   struct addrinfo hints, *res;
  18.   int i;
  19.  
  20.   if (gethostname(hostname, sizeof(hostname)) != 0) {
  21.     return 1;
  22.   }
  23.  
  24.   for (i=0; i<1000; i++) {
  25.     memset(&hints, 0, sizeof(hints));
  26.     hints.ai_family = AF_UNSPEC;
  27.     hints.ai_flags  = AI_CANONNAME;
  28.  
  29.     if (getaddrinfo(hostname, NULL, &hints, &res) != 0) {
  30.       return 2;
  31.     }
  32.     freeaddrinfo(res);
  33.   }
  34.  
  35.   return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment