tcpdump/tcpdump-3.9.8-gethostby.patch
2013-11-08 10:39:06 +01:00

94 lines
2.3 KiB
Diff

diff -up tcpdump-4.5.0/addrtoname.c.gethostby tcpdump-4.5.0/addrtoname.c
--- tcpdump-4.5.0/addrtoname.c.gethostby 2013-11-08 08:53:50.311792401 +0100
+++ tcpdump-4.5.0/addrtoname.c 2013-11-08 09:00:43.894765379 +0100
@@ -224,7 +224,6 @@ static u_int32_t f_localnet;
const char *
getname(const u_char *ap)
{
- register struct hostent *hp;
u_int32_t addr;
static struct hnamemem *p; /* static for longjmp() */
@@ -246,6 +245,28 @@ getname(const u_char *ap)
*/
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;
@@ -259,6 +280,7 @@ getname(const u_char *ap)
}
return (p->name);
}
+#endif
}
p->name = strdup(intoa(addr));
return (p->name);
@@ -272,7 +294,6 @@ getname(const u_char *ap)
const char *
getname6(const u_char *ap)
{
- register struct hostent *hp;
union {
struct in6_addr addr;
struct for_hash_addr {
@@ -297,6 +318,28 @@ getname6(const u_char *ap)
* 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;
+ sa.sin6_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, sizeof(addr), AF_INET6);
if (hp) {
char *dotp;
@@ -310,6 +353,7 @@ getname6(const u_char *ap)
}
return (p->name);
}
+#endif
}
cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);