aboutgitcodebugslistschat
path: root/util.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-21 14:48:03 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-22 23:20:37 +0200
commit1a20370b364ada675882e6a70d05b6e81418d64f (patch)
treec56f51f3666c17c231bdbb2b0f8116c2673736fb /util.h
parent3ff3a8a467fff1d4b234949e4dd3db618a9f8ed2 (diff)
downloadpasst-1a20370b364ada675882e6a70d05b6e81418d64f.tar
passt-1a20370b364ada675882e6a70d05b6e81418d64f.tar.gz
passt-1a20370b364ada675882e6a70d05b6e81418d64f.tar.bz2
passt-1a20370b364ada675882e6a70d05b6e81418d64f.tar.lz
passt-1a20370b364ada675882e6a70d05b6e81418d64f.tar.xz
passt-1a20370b364ada675882e6a70d05b6e81418d64f.tar.zst
passt-1a20370b364ada675882e6a70d05b6e81418d64f.zip
util, tcp: Add helper to display socket addresses
When reporting errors, we sometimes want to show a relevant socket address. Doing so by extracting the various relevant fields can be pretty awkward, so introduce a sockaddr_ntop() helper to make it simpler. For now we just have one user in tcp.c, but I have further upcoming patches which can make use of it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.h')
-rw-r--r--util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/util.h b/util.h
index 264423b..c8a357e 100644
--- a/util.h
+++ b/util.h
@@ -180,6 +180,20 @@ static inline const char *af_name(sa_family_t af)
}
}
+#define UINT16_STRLEN (sizeof("65535"))
+
+/* inet address (- '\0') + port (u16) (- '\0') + ':' + '\0' */
+#define SOCKADDR_INET_STRLEN \
+ (INET_ADDRSTRLEN-1 + UINT16_STRLEN-1 + sizeof(":"))
+
+/* inet6 address (- '\0') + port (u16) (- '\0') + '[' + ']' + ':' + '\0' */
+#define SOCKADDR_INET6_STRLEN \
+ (INET6_ADDRSTRLEN-1 + UINT16_STRLEN-1 + sizeof("[]:"))
+
+#define SOCKADDR_STRLEN MAX(SOCKADDR_INET_STRLEN, SOCKADDR_INET6_STRLEN)
+
+const char *sockaddr_ntop(const void *sa, char *dst, socklen_t size);
+
/**
* mod_sub() - Modular arithmetic subtraction
* @a: Minued, unsigned value < @m