diff options
author | Gleb Smirnoff <glebius@FreeBSD.org> | 2017-02-01 16:13:05 -0800 |
---|---|---|
committer | Gleb Smirnoff <glebius@FreeBSD.org> | 2017-02-01 16:13:05 -0800 |
commit | cd3c5880b13c9c25ad480ecafadbfe6e86a7c5c7 (patch) | |
tree | 9a72e5336f3a74a813ba07805c7d26aa341d2cbe /addrtoname.c | |
parent | 49b23c5a9b0198bb382dcf43c458d46fcf2fa809 (diff) | |
download | tcpdump-cd3c5880b13c9c25ad480ecafadbfe6e86a7c5c7.tar.gz |
Add support for libcasper library available on FreeBSD 11.0 and newer.
The patch allows tcpdump to run sandboxed and still do name resolution.
The code is obtained from FreeBSD tree, where it was developed by
Pawel Jakub Dawidek <pjd@FreeBSD.org>
Mariusz Zaborski <oshogbo@FreeBSD.org>
Diffstat (limited to 'addrtoname.c')
-rw-r--r-- | addrtoname.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/addrtoname.c b/addrtoname.c index 5831b346..c679c83f 100644 --- a/addrtoname.c +++ b/addrtoname.c @@ -26,6 +26,11 @@ #include "config.h" #endif +#ifdef HAVE_CASPER +#include <libcasper.h> +#include <casper/cap_dns.h> +#endif /* HAVE_CASPER */ + #include <netdissect-stdinc.h> #ifdef USE_ETHER_NTOHOST @@ -197,6 +202,9 @@ intoa(uint32_t addr) static uint32_t f_netmask; static uint32_t f_localnet; +#ifdef HAVE_CASPER +extern cap_channel_t *capdns; +#endif /* * Return a name for the IP address pointed to by ap. This address @@ -242,7 +250,13 @@ getname(netdissect_options *ndo, const u_char *ap) */ if (!ndo->ndo_nflag && (addr & f_netmask) == f_localnet) { - hp = gethostbyaddr((char *)&addr, 4, AF_INET); +#ifdef HAVE_CASPER + if (capdns != NULL) { + hp = cap_gethostbyaddr(capdns, (char *)&addr, 4, + AF_INET); + } else +#endif + hp = gethostbyaddr((char *)&addr, 4, AF_INET); if (hp) { char *dotp; @@ -297,7 +311,14 @@ getname6(netdissect_options *ndo, const u_char *ap) * Do not print names if -n was given. */ if (!ndo->ndo_nflag) { - hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6); +#ifdef HAVE_CASPER + if (capdns != NULL) { + hp = cap_gethostbyaddr(capdns, (char *)&addr, + sizeof(addr), AF_INET6); + } else +#endif + hp = gethostbyaddr((char *)&addr, sizeof(addr), + AF_INET6); if (hp) { char *dotp; |