From e6c957caaa0ca262528adb282357efcaef8b25b1 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Sun, 2 Jan 2005 12:04:45 +0000
Subject: [PATCH] Fix so that getnameinfo() is passed the address-specific
 structure size. This lets it work on Solaris (and probably other platforms)

--HG--
extra : convert_revision : b486b773f163af8462b0ef6565ac4285a54708eb
---
 dbutil.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/dbutil.c b/dbutil.c
index cf571180..ce43933a 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -357,6 +357,16 @@ unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport) {
 	unsigned int len;
 
 	len = sizeof(struct sockaddr_storage);
+	/* Some platforms such as Solaris 8 require that len is the length
+	 * of the specific structure. */
+	if (addr->ss_family == AF_INET) {
+		len = sizeof(struct sockaddr_in);
+	}
+#ifdef AF_INET6
+	if (addr->ss_family == AF_INET6) {
+		len = sizeof(struct sockaddr_in6);
+	}
+#endif
 
 	ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf), 
 			sbuf, sizeof(sbuf), NI_NUMERICSERV | NI_NUMERICHOST);
@@ -389,6 +399,16 @@ char* getaddrhostname(struct sockaddr_storage * addr) {
 	unsigned int len;
 
 	len = sizeof(struct sockaddr_storage);
+	/* Some platforms such as Solaris 8 require that len is the length
+	 * of the specific structure. */
+	if (addr->ss_family == AF_INET) {
+		len = sizeof(struct sockaddr_in);
+	}
+#ifdef AF_INET6
+	if (addr->ss_family == AF_INET6) {
+		len = sizeof(struct sockaddr_in6);
+	}
+#endif
 
 	ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf),
 			sbuf, sizeof(sbuf), NI_NUMERICSERV);
-- 
GitLab