tcpdump/0002-Use-getnameinfo-instead-of-gethostbyaddr.patch
Michal Sekletar 4ea394f9d4 Update to 4.6.2
Resolves #1124289
2014-10-21 15:22:50 +02:00

107 lines
2.7 KiB
Diff

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
index eb0b2ae..277751d 100644
--- a/addrtoname.c
+++ b/addrtoname.c
@@ -221,7 +221,6 @@ static uint32_t f_localnet;
const char *
getname(netdissect_options *ndo, const u_char *ap)
{
- register struct hostent *hp;
uint32_t addr;
static struct hnamemem *p; /* static for longjmp() */
@@ -243,6 +242,28 @@ getname(netdissect_options *ndo, const u_char *ap)
*/
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)) {
+ 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;
@@ -256,6 +277,7 @@ getname(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
p->name = strdup(intoa(addr));
return (p->name);
@@ -269,7 +291,6 @@ getname(netdissect_options *ndo, const u_char *ap)
const char *
getname6(netdissect_options *ndo, const u_char *ap)
{
- register struct hostent *hp;
union {
struct in6_addr addr;
struct for_hash_addr {
@@ -294,6 +315,28 @@ getname6(netdissect_options *ndo, const u_char *ap)
* Do not print names if -n was given.
*/
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)) {
+ 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, sizeof(addr), AF_INET6);
if (hp) {
char *dotp;
@@ -307,6 +350,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);
--
1.8.3.1