0b97fc6
diff -up tcpdump-3.9.8/addrtoname.c.gethostby tcpdump-3.9.8/addrtoname.c
0b97fc6
--- tcpdump-3.9.8/addrtoname.c.gethostby	2007-10-24 14:50:28.000000000 +0200
0b97fc6
+++ tcpdump-3.9.8/addrtoname.c	2007-10-24 16:58:04.000000000 +0200
0b97fc6
@@ -225,7 +225,6 @@ static u_int32_t f_localnet;
0b97fc6
 const char *
0b97fc6
 getname(const u_char *ap)
0b97fc6
 {
0b97fc6
-	register struct hostent *hp;
0b97fc6
 	u_int32_t addr;
0b97fc6
 	static struct hnamemem *p;		/* static for longjmp() */
0b97fc6
 
0b97fc6
@@ -247,6 +246,28 @@ getname(const u_char *ap)
0b97fc6
 	 */
0b97fc6
 	if (!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)) {
0b97fc6
+			if (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;
0b97fc6
@@ -260,6 +281,7 @@ getname(const u_char *ap)
0b97fc6
 			}
0b97fc6
 			return (p->name);
0b97fc6
 		}
0b97fc6
+#endif
0b97fc6
 	}
0b97fc6
 	p->name = strdup(intoa(addr));
0b97fc6
 	return (p->name);
0b97fc6
@@ -273,7 +295,6 @@ getname(const u_char *ap)
0b97fc6
 const char *
0b97fc6
 getname6(const u_char *ap)
0b97fc6
 {
0b97fc6
-	register struct hostent *hp;
0b97fc6
 	struct in6_addr addr;
0b97fc6
 	static struct h6namemem *p;		/* static for longjmp() */
0b97fc6
 	register const char *cp;
0b97fc6
@@ -292,6 +313,28 @@ getname6(const u_char *ap)
0b97fc6
 	 * Do not print names if -n was given.
0b97fc6
 	 */
0b97fc6
 	if (!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;
0b97fc6
+		sa.sin6_addr = addr;
0b97fc6
+		if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
0b97fc6
+					hbuf, sizeof (hbuf), NULL, 0, 0)) {
0b97fc6
+			if (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, sizeof(addr), AF_INET6);
0b97fc6
 		if (hp) {
0b97fc6
 			char *dotp;
0b97fc6
@@ -305,6 +348,7 @@ getname6(const u_char *ap)
0b97fc6
 			}
0b97fc6
 			return (p->name);
0b97fc6
 		}
0b97fc6
+#endif
0b97fc6
 	}
0b97fc6
 	cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
0b97fc6
 	p->name = strdup(cp);