You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
2.7 KiB

From ac19c334d4147d5fcdd4daa2ed6687340a2cd4b0 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Mon, 20 Oct 2014 14:12:46 +0200
Subject: [PATCH 02/13] Use getnameinfo instead of gethostbyaddr
---
addrtoname.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/addrtoname.c b/addrtoname.c
index df7c2ce..a1e360d 100644
--- a/addrtoname.c
+++ b/addrtoname.c
@@ -230,7 +230,6 @@ static uint32_t f_localnet;
const char *
getname(netdissect_options *ndo, const u_char *ap)
{
- register struct hostent *hp;
uint32_t addr;
struct hnamemem *p;
@@ -252,6 +251,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;
@@ -268,6 +289,7 @@ getname(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
p->name = strdup(intoa(addr));
if (p->name == NULL)
@@ -282,7 +304,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 {
@@ -307,6 +328,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;
@@ -323,6 +366,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);
--
2.13.5