Development discussion of WireGuard
 help / color / mirror / Atom feed
From: "Daniel Gröber" <dxld@darkboxed.org>
To: wireguard@lists.zx2c4.com
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>,
	"Daniel Gröber" <dxld@darkboxed.org>
Subject: [PATCH v2 6/6] wg: Simplify showconf_main by using print_sockaddr_inet
Date: Mon, 23 Oct 2023 19:09:00 +0200	[thread overview]
Message-ID: <20231023170900.131473-6-dxld@darkboxed.org> (raw)
In-Reply-To: <20231023170900.131473-1-dxld@darkboxed.org>

Signed-off-by: Daniel Gröber <dxld@darkboxed.org>
---
 src/showconf.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/src/showconf.c b/src/showconf.c
index c99a6a0..f2c6a68 100644
--- a/src/showconf.c
+++ b/src/showconf.c
@@ -23,8 +23,6 @@ int showconf_main(int argc, const char *argv[])
 {
 	char base64[WG_KEY_LEN_BASE64];
 	char ip[INET6_ADDRSTRLEN];
-	char host[4096 + 1], service[512 + 1];
-	socklen_t addr_len = 0;
 	struct wgdevice *device = NULL;
 	struct wgpeer *peer;
 	struct wgallowedip *allowedip;
@@ -77,19 +75,8 @@ int showconf_main(int argc, const char *argv[])
 		if (peer->first_allowedip)
 			printf("\n");
 
-		// TODO: use print_endpoint
-		if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6) {
-			if (peer->endpoint.addr.sa_family == AF_INET)
-				addr_len = sizeof(struct sockaddr_in);
-			else if (peer->endpoint.addr.sa_family == AF_INET6)
-				addr_len = sizeof(struct sockaddr_in6);
-			if (!getnameinfo(&peer->endpoint.addr, addr_len, host, sizeof(host), service, sizeof(service), NI_DGRAM | NI_NUMERICSERV | NI_NUMERICHOST)) {
-				if (peer->endpoint.addr.sa_family == AF_INET6 && strchr(host, ':'))
-					printf("Endpoint = [%s]:%s\n", host, service);
-				else
-					printf("Endpoint = %s:%s\n", host, service);
-			}
-		}
+		if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
+			printf("Endpoint = %s\n", print_sockaddr_inet(&peer->endpoint.addr_inet));
 
 		if (peer->persistent_keepalive_interval)
 			printf("PersistentKeepalive = %u\n", peer->persistent_keepalive_interval);
-- 
2.39.2


      parent reply	other threads:[~2023-10-23 17:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-23 17:08 [PATCH v2 1/6] uapi/linux: Add definitions for address/netdev bound listen sockets Daniel Gröber
2023-10-23 17:08 ` [PATCH v2 2/6] wg: Support binding to specific addr and iface for multihomed hosts Daniel Gröber
2023-10-23 17:08 ` [PATCH v2 3/6] wg: Store sockaddr listen port in net-byte-order as is conventional Daniel Gröber
2023-10-23 17:08 ` [PATCH v2 4/6] wg: Check sockaddr_inet field offsets against system sockaddr Daniel Gröber
2023-10-23 17:08 ` [PATCH v2 5/6] wg: Replace print_endpoint with print_sockaddr_inet Daniel Gröber
2023-10-23 17:09 ` Daniel Gröber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231023170900.131473-6-dxld@darkboxed.org \
    --to=dxld@darkboxed.org \
    --cc=Jason@zx2c4.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).