Tcpdump - pcap -不能嗅探端口5984上的数据包
Tcpdump - pcap - Cannot sniff packets on port 5984
抱歉,如果这是一个蹩脚的问题。我是tcpdump和pcap的新手。我使用pcap静态库来开发一个应用程序,该应用程序在指定端口上侦听TCP数据。我建立了一个小原型,它在嗅探通过端口80 (HTTP的默认值)发送的tcp数据包时工作得很好。但是,我想查看进出端口5984的HTTP数据包(这是CouchDB使用的默认端口)。由于某种原因,我的应用程序没有注意到/嗅探/看到这个端口上的任何数据包。由于我不是一个经验丰富的网络开发人员,我可能错过了一些基本的东西。
我不想粘贴整个应用程序在这里,但我可以添加任何代码,是必要的,以找到问题。请让我知道。
这是我的pcap过滤器表达式:
char filter_exp[] = "tcp port 5984";/* The filter expression */
过滤器在pcap会话上编译和设置没有问题。设置会话以混杂模式运行。
//get a pcap session
//args device, # of packets to capture, promisc mode, timeout, err buff
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %sn", dev, errbuf);
return(2);
//compile our filter
if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
fprintf(stderr, "Couldn't parse filter %s: %sn", filter_exp, pcap_geterr(handle));
return(2);
}
//set the filter
if (pcap_setfilter(handle, &fp) == -1) {
fprintf(stderr, "Couldn't install filter %s: %sn", filter_exp, pcap_geterr(handle));
return(2);
}
//begin sniffing packets. cnt -1: keep sniffing until err occurs
//last arg is optional. It can be used to pass additonal information to callback
pcap_loop(handle, -1, got_packet, NULL);
'got_packet'是我的回调函数。这将使用相同的过滤器多次调用,但端口80取代了5984。
使用Curl: $ curl http://localhost:5984/test
只是为了好玩,我尝试使用环回:$ curl http://127.0.0.1:5984/test
这两个都不会被我的pcap应用程序注意到。但是,如果我将过滤器更改为侦听端口80并执行$ curl http://www.google.com
我可以看到数据包通过。我忽略或不理解的是什么?
非常感谢!
尼克
如果数据包从您的Mac发送到相同的Mac—例如,如果您正在与"localhost"或127.0.0.1(这是同一件事—"localhost"解析为127.0.0.1)通信,则捕获lo0
,而不是en0
或en1
。到127.0.0.1的流量不会在任何真正的网络上发送,它会在内部环路返回到您的机器,因此您必须查看"环回"网络和"环回"接口。
(类似的答案适用于其他UN* x,除了在Linux上,环回接口只称为lo
,而不是lo0
。在Windows上没有对应的,在某些版本的UN*X上,例如Solaris 10和更早的版本,您无法捕获环回接口。
- boost::asio UDP 广播客户端仅接收"fast"数据包
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- 发送固定大小的 UDP 数据包
- pcap_handler回调仅在使用 NPCAP v0.9991 时包含空数据包
- 在 c++ 中解析数据包数据的最佳方法是什么?
- 接受函数在发送数据包时等待
- 如何在 omnet++ 中发送自定义数据包?
- 数据包访问实践
- 在C++中创建一个简单的数据包路由器,如何跟踪"客户端"?
- 德拉吉诺 LG01-S 收到异常数据包并停止工作
- 将数据包从C++服务器发送到NodeJs服务器时出现MessagePack解码错误
- 使用C++将UDP数据包存储在Structure中
- FFmpeg av_read_frame从音频流返回数据包
- 为什么操作系统正在更改我的数据包的指定传出端口
- 是否可以将多个结构作为一个数据包存储在一个函数中,然后传递给其他函数并在那里提取?
- recvfrom 只收到几个数据包,之后它进入等待状态
- 如何调试由 C++ 编写的 npm 数据包
- 如何在INET的应用层中发送广播数据包
- C++ 将字符串数据包转换为 iphdr语言 - 字符串数据包的格式应该是什么?
- Tcpdump - pcap -不能嗅探端口5984上的数据包