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