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