diff options
author | fadhil riyanto <me@fadev.org> | 2024-10-09 20:12:24 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-10-09 20:12:24 +0700 |
commit | 86177910e4861e4d207cb37928f04bd242811d4f (patch) | |
tree | 15f0ca5075a176f52f3f4647bde04502829e7fd8 /test | |
parent | a5b8cc013fac490806ba1a4e7616d91d2850fe1c (diff) |
test resolve domain name
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/ares.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ares.c b/test/ares.c new file mode 100644 index 0000000..5effffe --- /dev/null +++ b/test/ares.c @@ -0,0 +1,42 @@ + +#include <errno.h> +#include <netinet/in.h> +#include <stdio.h> +#include <stdlib.h> +#include <netdb.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <string.h> + +int main() +{ + struct addrinfo req; + void *ptr; + + memset(&req, 0, sizeof(req)); + + struct addrinfo *res, *i; + int ret = 0; + + char buf[NI_MAXHOST]; + + req.ai_family = AF_INET6; + req.ai_socktype = SOCK_DGRAM; + + ret = getaddrinfo("google.com", NULL, &req, &res); + if (ret == 0) { + while (res) { + memset(buf, 0, NI_MAXHOST); + + ptr = &((struct sockaddr_in6*)res->ai_addr)->sin6_addr; + + inet_ntop(AF_INET6, ptr, buf, NI_MAXHOST); + printf("%s\n", buf); + + res = res->ai_next; + } + } else { + printf("invalid %s\n", gai_strerror(ret)); + } +} |