2013-11-08 09:39:06 +00:00
|
|
|
diff -up tcpdump-4.5.0/addrtoname.c.gethostby tcpdump-4.5.0/addrtoname.c
|
2013-11-08 09:51:42 +00:00
|
|
|
--- tcpdump-4.5.0/addrtoname.c.gethostby 2013-11-08 09:03:52.166752012 +0100
|
|
|
|
+++ tcpdump-4.5.0/addrtoname.c 2013-11-08 09:04:57.792747210 +0100
|
2013-11-08 09:39:06 +00:00
|
|
|
@@ -224,7 +224,6 @@ static u_int32_t f_localnet;
|
2007-10-24 16:39:02 +00:00
|
|
|
const char *
|
|
|
|
getname(const u_char *ap)
|
|
|
|
{
|
|
|
|
- register struct hostent *hp;
|
|
|
|
u_int32_t addr;
|
|
|
|
static struct hnamemem *p; /* static for longjmp() */
|
|
|
|
|
2013-11-08 09:39:06 +00:00
|
|
|
@@ -246,6 +245,28 @@ getname(const u_char *ap)
|
2007-10-24 16:39:02 +00:00
|
|
|
*/
|
|
|
|
if (!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 (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;
|
2013-11-08 09:39:06 +00:00
|
|
|
@@ -259,6 +280,7 @@ getname(const u_char *ap)
|
2007-10-24 16:39:02 +00:00
|
|
|
}
|
|
|
|
return (p->name);
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
p->name = strdup(intoa(addr));
|
|
|
|
return (p->name);
|
2013-11-08 09:39:06 +00:00
|
|
|
@@ -272,7 +294,6 @@ getname(const u_char *ap)
|
2007-10-24 16:39:02 +00:00
|
|
|
const char *
|
|
|
|
getname6(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 {
|
|
|
|
@@ -297,6 +318,28 @@ getname6(const u_char *ap)
|
2007-10-24 16:39:02 +00:00
|
|
|
* Do not print names if -n was given.
|
|
|
|
*/
|
|
|
|
if (!nflag) {
|
|
|
|
+#ifdef HAVE_GETNAMEINFO
|
|
|
|
+ struct sockaddr_in6 sa;
|
|
|
|
+ char hbuf[NI_MAXHOST];
|
|
|
|
+
|
|
|
|
+ memset(&sa, 0, sizeof (sa));
|
|
|
|
+ sa.sin6_family = AF_INET6;
|
2013-11-08 09:51:42 +00:00
|
|
|
+ sa.sin6_addr = addr.addr;
|
2007-10-24 16:39:02 +00:00
|
|
|
+ if (!getnameinfo((struct sockaddr *)&sa, sizeof (sa),
|
|
|
|
+ hbuf, sizeof (hbuf), NULL, 0, 0)) {
|
|
|
|
+ if (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;
|
2013-11-08 09:39:06 +00:00
|
|
|
@@ -310,6 +353,7 @@ getname6(const u_char *ap)
|
2007-10-24 16:39:02 +00:00
|
|
|
}
|
|
|
|
return (p->name);
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
|
|
|
|
p->name = strdup(cp);
|