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

a4812e
diff --git a/addrtoname.c b/addrtoname.c
a4812e
index 33b9378..426839c 100644
a4812e
--- a/addrtoname.c
a4812e
+++ b/addrtoname.c
a4812e
@@ -277,7 +277,6 @@ extern cap_channel_t *capdns;
a4812e
 const char *
a4812e
 ipaddr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 {
a4812e
-	struct hostent *hp;
a4812e
 	uint32_t addr;
a4812e
 	struct hnamemem *p;
a4812e
 
a4812e
@@ -299,13 +298,29 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 	 */
a4812e
 	if (!ndo->ndo_nflag &&
a4812e
 	    (addr & f_netmask) == f_localnet) {
a4812e
-#ifdef HAVE_CASPER
a4812e
-		if (capdns != NULL) {
a4812e
-			hp = cap_gethostbyaddr(capdns, (char *)&addr, 4,
a4812e
-			    AF_INET);
a4812e
-		} else
a4812e
-#endif
a4812e
-			hp = gethostbyaddr((char *)&addr, 4, AF_INET);
a4812e
+#ifdef HAVE_GETNAMEINFO
a4812e
+		struct sockaddr_in sa;
a4812e
+		char hbuf[NI_MAXHOST];
a4812e
+
a4812e
+		memset(&sa, 0, sizeof (sa));
a4812e
+		sa.sin_family = AF_INET;
a4812e
+		sa.sin_addr.s_addr = addr;
a4812e
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
a4812e
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
a4812e
+			if (ndo->ndo_Nflag) {
a4812e
+				char *dotp;
a4812e
+
a4812e
+				/* Remove domain qualifications */
a4812e
+				dotp = strchr(hbuf, '.');
a4812e
+				if (dotp)
a4812e
+					*dotp = '\0';
a4812e
+			}
a4812e
+			p->name = strdup(hbuf);
a4812e
+			return p->name;
a4812e
+		}
a4812e
+#else
a4812e
+		struct hostent *hp;
a4812e
+		hp = gethostbyaddr((char *)&addr, 4, AF_INET);
a4812e
 		if (hp) {
a4812e
 			char *dotp;
a4812e
 
a4812e
@@ -321,6 +336,7 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 			}
a4812e
 			return (p->name);
a4812e
 		}
a4812e
+#endif
a4812e
 	}
a4812e
 	p->name = strdup(intoa(addr));
a4812e
 	if (p->name == NULL)
a4812e
@@ -336,7 +352,6 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 const char *
a4812e
 ip6addr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 {
a4812e
-	struct hostent *hp;
a4812e
 	union {
a4812e
 		nd_ipv6 addr;
a4812e
 		struct for_hash_addr {
a4812e
@@ -361,13 +376,29 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 	 * Do not print names if -n was given.
a4812e
 	 */
a4812e
 	if (!ndo->ndo_nflag) {
a4812e
-#ifdef HAVE_CASPER
a4812e
-		if (capdns != NULL) {
a4812e
-			hp = cap_gethostbyaddr(capdns, (char *)&addr,
a4812e
-			    sizeof(addr), AF_INET6);
a4812e
-		} else
a4812e
-#endif
a4812e
-			hp = gethostbyaddr((char *)&addr, sizeof(addr),
a4812e
+#ifdef HAVE_GETNAMEINFO
a4812e
+		struct sockaddr_in6 sa;
a4812e
+		char hbuf[NI_MAXHOST];
a4812e
+
a4812e
+		memset(&sa, 0, sizeof (sa));
a4812e
+		sa.sin6_family = AF_INET6;
a4812e
+		sa.sin6_addr = addr.addr;
a4812e
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
a4812e
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
a4812e
+			if (ndo->ndo_Nflag) {
a4812e
+				char *dotp;
a4812e
+
a4812e
+				/* Remove domain qualifications */
a4812e
+				dotp = strchr(hbuf, '.');
a4812e
+				if (dotp)
a4812e
+					*dotp = '\0';
a4812e
+			}
a4812e
+			p->name = strdup(hbuf);
a4812e
+			return p->name;
a4812e
+		}
a4812e
+#else
a4812e
+		struct hostent *hp;
a4812e
+		hp = gethostbyaddr((char *)&addr, sizeof(addr),
a4812e
 			    AF_INET6);
a4812e
 		if (hp) {
a4812e
 			char *dotp;
a4812e
@@ -384,6 +415,7 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
a4812e
 			}
a4812e
 			return (p->name);
a4812e
 		}
a4812e
+#endif
a4812e
 	}
a4812e
 	cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
a4812e
 	p->name = strdup(cp);