diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2021-02-05 04:38:17 +0300 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2021-02-05 04:38:17 +0300 |
commit | 3721f7e14449c4ef5d4aba8cb8a58fdb8d74c1df (patch) | |
tree | fcef890fc14104334856c9ad648a0eae27233fe7 | |
parent | 6c029fdf471262e92ebc9a69329a0c45814e2c2c (diff) |
test_getaddrinfo: also print port information
-rw-r--r-- | tests/test_getaddrinfo.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c index 179b43b..88dc890 100644 --- a/tests/test_getaddrinfo.c +++ b/tests/test_getaddrinfo.c @@ -32,8 +32,11 @@ static int doit(const char* host, const char* service) { fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error)); continue; } - if (*hostname != '\0') - printf("hostname: %s\n", hostname); + int port = 0; + if(res->ai_family == AF_INET) port = ((struct sockaddr_in*)res->ai_addr)->sin_port; + else if(res->ai_family == AF_INET6) port = ((struct sockaddr_in6*)res->ai_addr)->sin6_port; + port = ntohs(port); + printf("hostname: %s, port: %d\n", hostname, port); } freeaddrinfo(result); |