Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/haad/proxychains.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2012-07-16 03:21:22 +0400
committerrofl0r <retnyg@gmx.net>2012-07-16 03:21:22 +0400
commit6f56956715846d3430a0008749f08a4d8560919d (patch)
treefa7d78764201bc6e4d34aca109ba35d84de7fc84 /tests
parent037edbcb8ec34bf4a1966be139417ce64ebe535c (diff)
add test for getaddrinfo
Diffstat (limited to 'tests')
-rw-r--r--tests/test_getaddrinfo.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c
new file mode 100644
index 0000000..7581428
--- /dev/null
+++ b/tests/test_getaddrinfo.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#ifndef NI_MAXHOST
+#define NI_MAXHOST 1025
+#endif
+
+int main(void) {
+ struct addrinfo *result;
+ struct addrinfo *res;
+ int error;
+
+ /* resolve the domain name into a list of addresses */
+ error = getaddrinfo("www.example.com", NULL, NULL, &result);
+ if (error != 0)
+ {
+ fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
+ return EXIT_FAILURE;
+ }
+
+ /* loop over all returned results and do inverse lookup */
+ for (res = result; res != NULL; res = res->ai_next)
+ {
+ char hostname[NI_MAXHOST] = "";
+
+ error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
+ if (error != 0)
+ {
+ fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
+ continue;
+ }
+ if (*hostname != '\0')
+ printf("hostname: %s\n", hostname);
+ }
+
+ freeaddrinfo(result);
+ return EXIT_SUCCESS;
+}