9 Star 0 Fork 22

src-openEuler/tcpdump

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-0002-Use-getnameinfo-instead-of-gethostbyaddr.patch 2.72 KB
一键复制 编辑 原始数据 按行查看 历史
yangl777 提交于 2022-03-21 16:15 . update tcpdump to 4.99.1
diff --git a/addrtoname.c b/addrtoname.c
index 33b9378..426839c 100644
--- a/addrtoname.c
+++ b/addrtoname.c
@@ -277,7 +277,6 @@ extern cap_channel_t *capdns;
const char *
ipaddr_string(netdissect_options *ndo, const u_char *ap)
{
- struct hostent *hp;
uint32_t addr;
struct hnamemem *p;
@@ -299,13 +298,29 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
*/
if (!ndo->ndo_nflag &&
(addr & f_netmask) == f_localnet) {
-#ifdef HAVE_CASPER
- if (capdns != NULL) {
- hp = cap_gethostbyaddr(capdns, (char *)&addr, 4,
- AF_INET);
- } else
-#endif
- hp = gethostbyaddr((char *)&addr, 4, AF_INET);
+#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
+ struct hostent *hp;
+ hp = gethostbyaddr((char *)&addr, 4, AF_INET);
if (hp) {
char *dotp;
@@ -321,6 +336,7 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
p->name = strdup(intoa(addr));
if (p->name == NULL)
@@ -336,7 +352,6 @@ ipaddr_string(netdissect_options *ndo, const u_char *ap)
const char *
ip6addr_string(netdissect_options *ndo, const u_char *ap)
{
- struct hostent *hp;
union {
nd_ipv6 addr;
struct for_hash_addr {
@@ -361,13 +376,29 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
* Do not print names if -n was given.
*/
if (!ndo->ndo_nflag) {
-#ifdef HAVE_CASPER
- if (capdns != NULL) {
- hp = cap_gethostbyaddr(capdns, (char *)&addr,
- sizeof(addr), AF_INET6);
- } else
-#endif
- hp = gethostbyaddr((char *)&addr, sizeof(addr),
+#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
+ struct hostent *hp;
+ hp = gethostbyaddr((char *)&addr, sizeof(addr),
AF_INET6);
if (hp) {
char *dotp;
@@ -384,6 +415,7 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
}
return (p->name);
}
+#endif
}
cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/tcpdump.git
git@gitee.com:src-openeuler/tcpdump.git
src-openeuler
tcpdump
tcpdump
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385