Blame SOURCES/0002-Use-getnameinfo-instead-of-gethostbyaddr.patch

f6b043
From c48fba64fbbff9c75c79e32ab33aa65742c197d9 Mon Sep 17 00:00:00 2001
f6b043
From: rpm-build <rpm-build>
f6b043
Date: Mon, 20 Oct 2014 14:12:46 +0200
f6b043
Subject: [PATCH 2/8] Use getnameinfo instead of gethostbyaddr
f6b043
f6b043
---
f6b043
 addrtoname.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
f6b043
 1 file changed, 46 insertions(+), 2 deletions(-)
f6b043
f6b043
diff --git a/addrtoname.c b/addrtoname.c
f6b043
index 6975b71..949acb7 100644
f6b043
--- a/addrtoname.c
f6b043
+++ b/addrtoname.c
f6b043
@@ -220,7 +220,6 @@ static uint32_t f_localnet;
f6b043
 const char *
f6b043
 getname(netdissect_options *ndo, const u_char *ap)
f6b043
 {
f6b043
-	register struct hostent *hp;
f6b043
 	uint32_t addr;
f6b043
 	struct hnamemem *p;
f6b043
 
f6b043
@@ -242,6 +241,28 @@ getname(netdissect_options *ndo, const u_char *ap)
f6b043
 	 */
f6b043
 	if (!ndo->ndo_nflag &&
f6b043
 	    (addr & f_netmask) == f_localnet) {
f6b043
+#ifdef HAVE_GETNAMEINFO
f6b043
+		struct sockaddr_in sa;
f6b043
+		char hbuf[NI_MAXHOST];
f6b043
+
f6b043
+		memset(&sa, 0, sizeof (sa));
f6b043
+		sa.sin_family = AF_INET;
f6b043
+		sa.sin_addr.s_addr = addr;
f6b043
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
f6b043
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
f6b043
+			if (ndo->ndo_Nflag) {
f6b043
+				char *dotp;
f6b043
+
f6b043
+				/* Remove domain qualifications */
f6b043
+				dotp = strchr(hbuf, '.');
f6b043
+				if (dotp)
f6b043
+					*dotp = '\0';
f6b043
+			}
f6b043
+			p->name = strdup(hbuf);
f6b043
+			return p->name;
f6b043
+		}
f6b043
+#else
f6b043
+		register struct hostent *hp;
f6b043
 		hp = gethostbyaddr((char *)&addr, 4, AF_INET);
f6b043
 		if (hp) {
f6b043
 			char *dotp;
f6b043
@@ -258,6 +279,7 @@ getname(netdissect_options *ndo, const u_char *ap)
f6b043
 			}
f6b043
 			return (p->name);
f6b043
 		}
f6b043
+#endif
f6b043
 	}
f6b043
 	p->name = strdup(intoa(addr));
f6b043
 	if (p->name == NULL)
f6b043
@@ -272,7 +294,6 @@ getname(netdissect_options *ndo, const u_char *ap)
f6b043
 const char *
f6b043
 getname6(netdissect_options *ndo, const u_char *ap)
f6b043
 {
f6b043
-	register struct hostent *hp;
f6b043
 	union {
f6b043
 		struct in6_addr addr;
f6b043
 		struct for_hash_addr {
f6b043
@@ -297,6 +318,28 @@ getname6(netdissect_options *ndo, const u_char *ap)
f6b043
 	 * Do not print names if -n was given.
f6b043
 	 */
f6b043
 	if (!ndo->ndo_nflag) {
f6b043
+#ifdef HAVE_GETNAMEINFO
f6b043
+		struct sockaddr_in6 sa;
f6b043
+		char hbuf[NI_MAXHOST];
f6b043
+
f6b043
+		memset(&sa, 0, sizeof (sa));
f6b043
+		sa.sin6_family = AF_INET6;
f6b043
+		sa.sin6_addr = addr.addr;
f6b043
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
f6b043
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
f6b043
+			if (ndo->ndo_Nflag) {
f6b043
+				char *dotp;
f6b043
+
f6b043
+				/* Remove domain qualifications */
f6b043
+				dotp = strchr(hbuf, '.');
f6b043
+				if (dotp)
f6b043
+					*dotp = '\0';
f6b043
+			}
f6b043
+			p->name = strdup(hbuf);
f6b043
+			return p->name;
f6b043
+		}
f6b043
+#else
f6b043
+                register struct hostent *hp;
f6b043
 		hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6);
f6b043
 		if (hp) {
f6b043
 			char *dotp;
f6b043
@@ -313,6 +356,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
f6b043
 			}
f6b043
 			return (p->name);
f6b043
 		}
f6b043
+#endif
f6b043
 	}
f6b043
 	cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
f6b043
 	p->name = strdup(cp);
f6b043
-- 
f6b043
2.9.3
f6b043