Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* gcc -W -Wall -o test test.c && valgrind --leak-check=full --show-reachable=yes ./test
- */
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <sys/param.h>
- #include <netdb.h>
- int main(int argc, char **argv)
- {
- (void)argc;
- (void)argv;
- char hostname[MAXHOSTNAMELEN+1];
- struct addrinfo hints, *res;
- int i;
- if (gethostname(hostname, sizeof(hostname)) != 0) {
- return 1;
- }
- for (i=0; i<1000; i++) {
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_flags = AI_CANONNAME;
- if (getaddrinfo(hostname, NULL, &hints, &res) != 0) {
- return 2;
- }
- freeaddrinfo(res);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment