diff options
author | fadhil riyanto <me@fadev.org> | 2024-10-10 07:10:12 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-10-10 07:10:12 +0700 |
commit | 5df217fbf0fc95c4ec8399506341e1880ccde416 (patch) | |
tree | 8eb4d2b3ad3a570e3e29edaaa3af86df01090dae /test | |
parent | f701818059405ed36669280e40aa668ccded8e03 (diff) |
test resolve by AF_UNSPEC
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/ares.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/test/ares.c b/test/ares.c index 5effffe..4881eed 100644 --- a/test/ares.c +++ b/test/ares.c @@ -21,18 +21,26 @@ int main() char buf[NI_MAXHOST]; - req.ai_family = AF_INET6; + req.ai_family = AF_UNSPEC; req.ai_socktype = SOCK_DGRAM; - ret = getaddrinfo("google.com", NULL, &req, &res); + ret = getaddrinfo("fb.com", NULL, &req, &res); if (ret == 0) { while (res) { memset(buf, 0, NI_MAXHOST); - ptr = &((struct sockaddr_in6*)res->ai_addr)->sin6_addr; + if (res->ai_family == AF_INET6) { + ptr = &((struct sockaddr_in6*)res->ai_addr)->sin6_addr; + + inet_ntop(AF_INET6, ptr, buf, NI_MAXHOST); + printf("%s\n", buf); + } else if (res->ai_family == AF_INET) { + ptr = &((struct sockaddr_in*)res->ai_addr)->sin_addr; + + inet_ntop(AF_INET, ptr, buf, NI_MAXHOST); + printf("%s\n", buf); + } - inet_ntop(AF_INET6, ptr, buf, NI_MAXHOST); - printf("%s\n", buf); res = res->ai_next; } |