From ea20b4ec24c2206ddabfe240025fbe383142623a Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 18 Mar 2014 20:27:14 -0700 Subject: [PATCH] PORTMAP client: Parse and print the actual sockaddr that UADDR2TADDR returned --- examples/portmap-client.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/portmap-client.c b/examples/portmap-client.c index 1c3b240..a7cf7c2 100644 --- a/examples/portmap-client.c +++ b/examples/portmap-client.c @@ -34,9 +34,11 @@ #include #endif +#include #include #include #include +#include #include #include "libnfs-zdr.h" #include "libnfs.h" @@ -189,6 +191,8 @@ void pmap3_uaddr2taddr_cb(struct rpc_context *rpc, int status, void *data, void { struct client *client = private_data; struct pmap3_netbuf *nb = data; + struct sockaddr_storage *ss; + char host[256], port[6]; int i; if (status == RPC_STATUS_ERROR) { @@ -210,6 +214,19 @@ void pmap3_uaddr2taddr_cb(struct rpc_context *rpc, int status, void *data, void } } printf("\n"); + printf(" ---\n"); + ss = (struct sockaddr_storage *)&nb->buf.buf_val[0]; + getnameinfo((struct sockaddr *)ss, sizeof(struct sockaddr_in6), + &host[0], sizeof(host), &port[0], sizeof(port), + NI_NUMERICHOST|NI_NUMERICSERV); + switch (ss->ss_family) { + case AF_INET: + printf(" IPv4: %s:%s\n", &host[0], &port[0]); + break; + case AF_INET6: + printf(" IPv6: %s:%s\n", &host[0], &port[0]); + break; + } client->is_finished = 1; } -- 2.34.1