tcpdump/0002-Use-getnameinfo-instead-of-gethostbyaddr.patch

107 lines
2.7 KiB
Diff
Raw Normal View History

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