tcpdump/tcpdump-3.9.8-gethostby.patch
Miroslav Lichvar 0b97fc6175 - update to 3.9.8
- don't use gethostbyaddr
- fix default user in man page
2007-10-24 16:39:02 +00:00

94 lines
2.3 KiB
Diff

diff -up tcpdump-3.9.8/addrtoname.c.gethostby tcpdump-3.9.8/addrtoname.c
--- tcpdump-3.9.8/addrtoname.c.gethostby 2007-10-24 14:50:28.000000000 +0200
+++ tcpdump-3.9.8/addrtoname.c 2007-10-24 16:58:04.000000000 +0200
@@ -225,7 +225,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() */
@@ -247,6 +246,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;
@@ -260,6 +281,7 @@ getname(const u_char *ap)
}
return (p->name);
}
+#endif
}
p->name = strdup(intoa(addr));
return (p->name);
@@ -273,7 +295,6 @@ getname(const u_char *ap)
const char *
getname6(const u_char *ap)
{
- register struct hostent *hp;
struct in6_addr addr;
static struct h6namemem *p; /* static for longjmp() */
register const char *cp;
@@ -292,6 +313,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;
@@ -305,6 +348,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);