|
|
106355 |
From ac19c334d4147d5fcdd4daa2ed6687340a2cd4b0 Mon Sep 17 00:00:00 2001
|
|
|
106355 |
From: rpm-build <rpm-build>
|
|
|
106355 |
Date: Mon, 20 Oct 2014 14:12:46 +0200
|
|
|
106355 |
Subject: [PATCH 02/13] Use getnameinfo instead of gethostbyaddr
|
|
|
106355 |
|
|
|
106355 |
---
|
|
|
106355 |
addrtoname.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
|
|
|
106355 |
1 file changed, 46 insertions(+), 2 deletions(-)
|
|
|
106355 |
|
|
|
106355 |
diff --git a/addrtoname.c b/addrtoname.c
|
|
|
106355 |
index df7c2ce..a1e360d 100644
|
|
|
106355 |
--- a/addrtoname.c
|
|
|
106355 |
+++ b/addrtoname.c
|
|
|
106355 |
@@ -230,7 +230,6 @@ static uint32_t f_localnet;
|
|
|
106355 |
const char *
|
|
|
106355 |
getname(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
{
|
|
|
106355 |
- register struct hostent *hp;
|
|
|
106355 |
uint32_t addr;
|
|
|
106355 |
struct hnamemem *p;
|
|
|
106355 |
|
|
|
106355 |
@@ -252,6 +251,28 @@ getname(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
*/
|
|
|
106355 |
if (!ndo->ndo_nflag &&
|
|
|
106355 |
(addr & f_netmask) == f_localnet) {
|
|
|
106355 |
+#ifdef HAVE_GETNAMEINFO
|
|
|
106355 |
+ struct sockaddr_in sa;
|
|
|
106355 |
+ char hbuf[NI_MAXHOST];
|
|
|
106355 |
+
|
|
|
106355 |
+ memset(&sa, 0, sizeof (sa));
|
|
|
106355 |
+ sa.sin_family = AF_INET;
|
|
|
106355 |
+ sa.sin_addr.s_addr = addr;
|
|
|
106355 |
+ if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
|
|
|
106355 |
+ hbuf, sizeof (hbuf), NULL, 0, 0)) {
|
|
|
106355 |
+ if (ndo->ndo_Nflag) {
|
|
|
106355 |
+ char *dotp;
|
|
|
106355 |
+
|
|
|
106355 |
+ /* Remove domain qualifications */
|
|
|
106355 |
+ dotp = strchr(hbuf, '.');
|
|
|
106355 |
+ if (dotp)
|
|
|
106355 |
+ *dotp = '\0';
|
|
|
106355 |
+ }
|
|
|
106355 |
+ p->name = strdup(hbuf);
|
|
|
106355 |
+ return p->name;
|
|
|
106355 |
+ }
|
|
|
106355 |
+#else
|
|
|
106355 |
+ register struct hostent *hp;
|
|
|
106355 |
hp = gethostbyaddr((char *)&addr, 4, AF_INET);
|
|
|
106355 |
if (hp) {
|
|
|
106355 |
char *dotp;
|
|
|
106355 |
@@ -268,6 +289,7 @@ getname(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
}
|
|
|
106355 |
return (p->name);
|
|
|
106355 |
}
|
|
|
106355 |
+#endif
|
|
|
106355 |
}
|
|
|
106355 |
p->name = strdup(intoa(addr));
|
|
|
106355 |
if (p->name == NULL)
|
|
|
106355 |
@@ -282,7 +304,6 @@ getname(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
const char *
|
|
|
106355 |
getname6(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
{
|
|
|
106355 |
- register struct hostent *hp;
|
|
|
106355 |
union {
|
|
|
106355 |
struct in6_addr addr;
|
|
|
106355 |
struct for_hash_addr {
|
|
|
106355 |
@@ -307,6 +328,28 @@ getname6(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
* Do not print names if -n was given.
|
|
|
106355 |
*/
|
|
|
106355 |
if (!ndo->ndo_nflag) {
|
|
|
106355 |
+#ifdef HAVE_GETNAMEINFO
|
|
|
106355 |
+ struct sockaddr_in6 sa;
|
|
|
106355 |
+ char hbuf[NI_MAXHOST];
|
|
|
106355 |
+
|
|
|
106355 |
+ memset(&sa, 0, sizeof (sa));
|
|
|
106355 |
+ sa.sin6_family = AF_INET6;
|
|
|
106355 |
+ sa.sin6_addr = addr.addr;
|
|
|
106355 |
+ if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
|
|
|
106355 |
+ hbuf, sizeof (hbuf), NULL, 0, 0)) {
|
|
|
106355 |
+ if (ndo->ndo_Nflag) {
|
|
|
106355 |
+ char *dotp;
|
|
|
106355 |
+
|
|
|
106355 |
+ /* Remove domain qualifications */
|
|
|
106355 |
+ dotp = strchr(hbuf, '.');
|
|
|
106355 |
+ if (dotp)
|
|
|
106355 |
+ *dotp = '\0';
|
|
|
106355 |
+ }
|
|
|
106355 |
+ p->name = strdup(hbuf);
|
|
|
106355 |
+ return p->name;
|
|
|
106355 |
+ }
|
|
|
106355 |
+#else
|
|
|
106355 |
+ register struct hostent *hp;
|
|
|
106355 |
hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6);
|
|
|
106355 |
if (hp) {
|
|
|
106355 |
char *dotp;
|
|
|
106355 |
@@ -323,6 +366,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
|
|
|
106355 |
}
|
|
|
106355 |
return (p->name);
|
|
|
106355 |
}
|
|
|
106355 |
+#endif
|
|
|
106355 |
}
|
|
|
106355 |
cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
|
|
|
106355 |
p->name = strdup(cp);
|
|
|
106355 |
--
|
|
|
106355 |
2.13.5
|
|
|
106355 |
|