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

ce5013
From ac19c334d4147d5fcdd4daa2ed6687340a2cd4b0 Mon Sep 17 00:00:00 2001
8d0d63
From: rpm-build <rpm-build>
8d0d63
Date: Mon, 20 Oct 2014 14:12:46 +0200
ce5013
Subject: [PATCH 02/13] Use getnameinfo instead of gethostbyaddr
8d0d63
8d0d63
---
8d0d63
 addrtoname.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
8d0d63
 1 file changed, 46 insertions(+), 2 deletions(-)
8d0d63
8d0d63
diff --git a/addrtoname.c b/addrtoname.c
ce5013
index df7c2ce..a1e360d 100644
8d0d63
--- a/addrtoname.c
8d0d63
+++ b/addrtoname.c
ce5013
@@ -230,7 +230,6 @@ static uint32_t f_localnet;
75b7d9
 const char *
8d0d63
 getname(netdissect_options *ndo, const u_char *ap)
75b7d9
 {
75b7d9
-	register struct hostent *hp;
8d0d63
 	uint32_t addr;
8d0d63
 	struct hnamemem *p;
75b7d9
 
ce5013
@@ -252,6 +251,28 @@ getname(netdissect_options *ndo, const u_char *ap)
75b7d9
 	 */
8d0d63
 	if (!ndo->ndo_nflag &&
75b7d9
 	    (addr & f_netmask) == f_localnet) {
75b7d9
+#ifdef HAVE_GETNAMEINFO
75b7d9
+		struct sockaddr_in sa;
75b7d9
+		char hbuf[NI_MAXHOST];
75b7d9
+
75b7d9
+		memset(&sa, 0, sizeof (sa));
75b7d9
+		sa.sin_family = AF_INET;
75b7d9
+		sa.sin_addr.s_addr = addr;
75b7d9
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
75b7d9
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
8d0d63
+			if (ndo->ndo_Nflag) {
75b7d9
+				char *dotp;
75b7d9
+
75b7d9
+				/* Remove domain qualifications */
75b7d9
+				dotp = strchr(hbuf, '.');
75b7d9
+				if (dotp)
75b7d9
+					*dotp = '\0';
75b7d9
+			}
75b7d9
+			p->name = strdup(hbuf);
75b7d9
+			return p->name;
75b7d9
+		}
75b7d9
+#else
75b7d9
+		register struct hostent *hp;
75b7d9
 		hp = gethostbyaddr((char *)&addr, 4, AF_INET);
75b7d9
 		if (hp) {
75b7d9
 			char *dotp;
ce5013
@@ -268,6 +289,7 @@ getname(netdissect_options *ndo, const u_char *ap)
75b7d9
 			}
75b7d9
 			return (p->name);
75b7d9
 		}
75b7d9
+#endif
75b7d9
 	}
75b7d9
 	p->name = strdup(intoa(addr));
8d0d63
 	if (p->name == NULL)
ce5013
@@ -282,7 +304,6 @@ getname(netdissect_options *ndo, const u_char *ap)
75b7d9
 const char *
8d0d63
 getname6(netdissect_options *ndo, const u_char *ap)
75b7d9
 {
75b7d9
-	register struct hostent *hp;
75b7d9
 	union {
75b7d9
 		struct in6_addr addr;
75b7d9
 		struct for_hash_addr {
ce5013
@@ -307,6 +328,28 @@ getname6(netdissect_options *ndo, const u_char *ap)
75b7d9
 	 * Do not print names if -n was given.
75b7d9
 	 */
8d0d63
 	if (!ndo->ndo_nflag) {
75b7d9
+#ifdef HAVE_GETNAMEINFO
75b7d9
+		struct sockaddr_in6 sa;
75b7d9
+		char hbuf[NI_MAXHOST];
75b7d9
+
75b7d9
+		memset(&sa, 0, sizeof (sa));
75b7d9
+		sa.sin6_family = AF_INET6;
75b7d9
+		sa.sin6_addr = addr.addr;
75b7d9
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
75b7d9
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
8d0d63
+			if (ndo->ndo_Nflag) {
75b7d9
+				char *dotp;
75b7d9
+
75b7d9
+				/* Remove domain qualifications */
75b7d9
+				dotp = strchr(hbuf, '.');
75b7d9
+				if (dotp)
75b7d9
+					*dotp = '\0';
75b7d9
+			}
75b7d9
+			p->name = strdup(hbuf);
75b7d9
+			return p->name;
75b7d9
+		}
75b7d9
+#else
8d0d63
+                register struct hostent *hp;
75b7d9
 		hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6);
75b7d9
 		if (hp) {
75b7d9
 			char *dotp;
ce5013
@@ -323,6 +366,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
75b7d9
 			}
75b7d9
 			return (p->name);
75b7d9
 		}
75b7d9
+#endif
75b7d9
 	}
8d0d63
 	cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
75b7d9
 	p->name = strdup(cp);
8d0d63
-- 
ce5013
2.13.5
8d0d63