- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想学习如何在用户空间处理数据包。因此,我研究了oxygen libnetfilter_queue文档中的示例队列处理程序。 [LINK]
所以我构建了防火墙来将传入的 ICMP 数据包发送到队列。我还从另一台 PC 向我的 PC 发送了 ping 并启动了该程序。
但是程序在接收请求期间停止了。 - 为什么?
这是设置:
<小时/>-1- 防火墙:我的防火墙将所有传入的 ICMP 数据包发送到队列套接字 0
Chain INPUT (policy ACCEPT)
target prot opt source destination
NFQUEUE icmp -- anywhere anywhere NFQUEUE num 0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
-2- 我对我的电脑执行了 ping 操作,并使用wireshark 测试了数据包的存在。 - 我收到了数据包。
-3- 队列句柄程序的代码。我添加了一些 printf 输出来显示程序卡在哪里。通常,该程序会接收数据包并打印有关其 header 和数据的信息。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <linux/types.h>
#include <linux/netfilter.h> /* for NF_ACCEPT */
#include <libnetfilter_queue/libnetfilter_queue.h>
/* returns packet id */
static u_int32_t print_pkt (struct nfq_data *tb)
{
int id = 0;
struct nfqnl_msg_packet_hdr *ph;
struct nfqnl_msg_packet_hw *hwph;
u_int32_t mark,ifi;
int ret;
char *data;
ph = nfq_get_msg_packet_hdr(tb);
if (ph) {
id = ntohl(ph->packet_id);
printf("hw_protocol=0x%04x hook=%u id=%u ",
ntohs(ph->hw_protocol), ph->hook, id);
}
hwph = nfq_get_packet_hw(tb);
if (hwph) {
int i, hlen = ntohs(hwph->hw_addrlen);
printf("hw_src_addr=");
for (i = 0; i < hlen-1; i++)
printf("%02x:", hwph->hw_addr[i]);
printf("%02x ", hwph->hw_addr[hlen-1]);
}
mark = nfq_get_nfmark(tb);
if (mark)
printf("mark=%u ", mark);
ifi = nfq_get_indev(tb);
if (ifi)
printf("indev=%u ", ifi);
ifi = nfq_get_outdev(tb);
if (ifi)
printf("outdev=%u ", ifi);
ifi = nfq_get_physindev(tb);
if (ifi)
printf("physindev=%u ", ifi);
ifi = nfq_get_physoutdev(tb);
if (ifi)
printf("physoutdev=%u ", ifi);
ret = nfq_get_payload(tb, &data);
if (ret >= 0)
printf("payload_len=%d ", ret);
fputc('\n', stdout);
return id;
}
static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
struct nfq_data *nfa, void *data)
{
u_int32_t id = print_pkt(nfa);
printf("entering callback\n");
return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
}
int main(int argc, char **argv)
{
struct nfq_handle *h;
struct nfq_q_handle *qh;
int fd = 0;
int rv;
char buf[4096] __attribute__ ((aligned));
printf("opening library handle\n");
h = nfq_open();
if (!h) {
fprintf(stderr, "error during nfq_open()\n");
exit(1);
}
printf("unbinding existing nf_queue handler for AF_INET (if any)\n");
if (nfq_unbind_pf(h, AF_INET) < 0) {
fprintf(stderr, "error during nfq_unbind_pf()\n");
exit(1);
}
printf("binding nfnetlink_queue as nf_queue handler for AF_INET\n");
if (nfq_bind_pf(h, AF_INET) < 0) {
fprintf(stderr, "error during nfq_bind_pf()\n");
exit(1);
}
printf("binding this socket to queue '0'\n");
qh = nfq_create_queue(h, 1, &cb, NULL);
if (!qh) {
fprintf(stderr, "error during nfq_create_queue()\n");
exit(1);
}
printf("setting copy_packet mode\n");
if (nfq_set_mode(qh, NFQNL_COPY_PACKET, 0xffff) < 0) { /* nfg_set_mode stellt ein, welche Pakete in dieses Programm geladen... */
fprintf(stderr, "can't set packet_copy mode\n"); /* ...werden sollen. Hier werden metadata und data in das Programm geladen... */
exit(1); /* Die Funktion gibt bei einem Fehler -1 zurück. */
}
fd = nfq_fd(h);
printf("DEBUG: The programm processed nfq_fd(h)!\n nfg_fd is: %u \n", fd);
rv = recv(fd, buf, sizeof(buf), 0); // temporär kopiert
printf("DEBUG: The programm arrived the receiver!\n recv is: %u \n", rv);
while ((rv = recv(fd, buf, sizeof(buf), 0)) && rv >= 0) {
printf("pkt received\n");
nfq_handle_packet(h, buf, rv);
}
printf("unbinding from queue 0\n");
nfq_destroy_queue(qh);
#ifdef INSANE
/* normally, applications SHOULD NOT issue this command, since
* it detaches other programs/sockets from AF_INET, too ! */
printf("unbinding from AF_INET\n");
nfq_unbind_pf(h, AF_INET);
#endif
printf("closing library handle\n");
nfq_close(h); /* closing the handler */
exit(0);
}
-4-这是我执行程序时的输出。程序在接收请求之前/期间停止。
opening library handle
unbinding existing nf_queue handler for AF_INET (if any)
binding nfnetlink_queue as nf_queue handler for AF_INET
binding this socket to queue '0'
setting copy_packet mode
DEBUG: The programm processed nfq_fd(h)!
nfg_fd is: 3
我希望这些信息有助于理解我想要做什么。关于 libnetfilte_queue 的主要文档在 recv 命令中非常简短。
很高兴找到这个论坛,4 特拉斯:)
最佳答案
终于找到问题所在了。不知何故,我不小心将这一行中处理程序的 NFQUEUE 编号更改为 1:
qh = nfq_create_queue(h, 1, &cb, NULL);
结果,程序等待来自NFQUEUE num 1的数据包,但我的防火墙将所有数据包发送到NFQUEUE num 0。
更正后的行:
qh = nfq_create_queue(h, 0, &cb, NULL);
天哪...这是一个愚蠢的错误;)
我要感谢所有考虑我问题的人! - 4特拉斯
关于c - iptables 的队列处理程序 : Why does it stuck during receive ICMP packets?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22093087/
Packet packet = new Packet(); while(packet != null ) { packet = jpcap.get
我有一个 python 脚本,它使用 dpkt 捕获以太网上的数据包,但我如何区分哪些数据包是 tcp,哪些是 udp。 最终,我希望获得在时间间隔内建立的每个 tcp 连接的数据包列表。 我的代码是
当我尝试将电缆与网络摄像头连接时,系统提示电缆无法连接到该端口。有人能帮我拿一下这个吗?
我正在尝试为 IPv6 建立 TCP 握手。 SYN 数据包被发送。接口(interface)收到SYN/ACK。 我对收到的数据包进行了十六进制转储,还对 pkt.show() 进行了处理。我得到以
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我在我的 Android 应用程序中使用 aSmack 与我的 XMPP 服务器通信,我打开了 Smack 的调试,这样我就可以看到所有 XML 的来来去去。我的问题是我正在使用 PacketList
自从升级到 Xcode 4.2 以来,我经常遇到错误,尝试调试应用程序失败,并显示消息“未知数据包回复:环境数据包“超时”。”重新启动设备并不能始终解决问题(尽管有时可以解决),重新启动 Xcode
我得到了一个派生自 sf::Packet 的类,它在其构造函数中传递了一个引用 iots 类型的 Integer。现在在构造函数中,我尝试将 Integer 添加到 sf::Packet 的数据中,如
我正在使用 Debian 操作系统。我正在编写网络仿真程序,我想获取所有数据包并停止 Debian从响应任何发送的数据包。 到目前为止,我已经打开了一个套接字,并且收到了所有数据包,但 Debian
对于一个应用程序,我需要能够创建一个多用户聊天室并加入其中。聊天服务器是一个 openfire 服务器。 我曾经有过: MultiUserChat chat = new MultiUserChat(c
我正在研究 中的核心音频转换服务 Learning Core Audio 我对他们 sample code 中的这个例子感到震惊: while(1) { // wrap the destina
我在my.cnf中添加了如下内容 [mysqld] max_allowed_packet=32M [mysql] max_allowed_packet=32M 而且我还在 JDBC 查询中添加了以下内
我需要测试 FTP 应用程序的数据包丢失情况。我用了Wireshark数据包嗅探器,我得到了 TCP 流。 如何使用 Wireshark 查找丢包情况? 最佳答案 数据包丢失和其他相关指标(例如误码率
每个人。这就是我们的门记录系统 Falco。当员工在读卡器上刷他/她的 ID 时,信号会传送到 Falco 服务器并将数据(卡 ID、时间)输入数据库。 Falco 的报告真的没有帮助,所以我们的人力
我正在研究 iSCSI 协议(protocol),现在我处于使用 Wireshark 捕获要查看的数据包的阶段,哪些数据包用于维护事件 session ,以及当我将文件复制到我的逻辑卷时,哪些数据包被
我无法理解网络上的任何人如何使用数据包嗅探器。 我对网络的工作原理知之甚少,但让我这样说吧:假设 postman 过来把包裹送到我家门口。为什么我可以翻遍他的所有其他包裹并环顾四周? postman
我已经看到(通过实际读取 tun 设备)Linux 上的 tun 驱动程序可以在一次读取中返回多个 IP 数据包。反之亦然 - 您可以在一次写入 tun 设备中写入多个 IP 数据包吗? 最佳答案 实
这个问题确实集中在我的问题上,与我在该主题上找到的任何其他问题无关。 PSA:当我说“数据包”时,我的意思是在单个 socket.recv(maxsize) 中接收到的完整字符串 我在 Java(我的
我想提高数据包传输性能。在此之前我使用原始套接字,现在我研究 packet_mmap。我有数据包(帧),我已经从另一台 PC 的内核模块中捕获了这些数据包(帧),并将其放入当前 PC,现在我想通过以下
我正在尝试使用带有一些标志的 tshark,并为每个过滤的跟踪获取时间戳。我正在使用它来过滤系统中的所有 DNS 查询。我无法获得时间戳以及过滤器工作。例如,如果我尝试类似 tshark -t ad
我是一名优秀的程序员,十分优秀!