0
A
回答
2
沒有必要編寫自己的netfilter模塊。你可以從用戶空間使用來自iptables的QUEUE目標,並編寫一個處理隊列的守護程序。
這方面的例子相對較少,但有些確實存在。它通常用於過濾,但你也可以(我相信)重新輸入修改的數據包(至少在iptables的mangle表中)。
1
試試下面的程序
寫iptables規則來傳遞數據包到用戶空間包
# iptables -A INPUT -p TCP -j QUEUE
編譯和執行爲
$ gcc test.c -lipq
$ sudo ./a.out
源代碼
#include <netinet/in.h>
#include <linux/netfilter.h>
#include <libipq.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 2048
static void die(struct ipq_handle *h)
{
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}
int main(int argc, char **argv)
{
int status, i=0;
unsigned char buf[BUFSIZE];
struct ipq_handle *h;
h = ipq_create_handle(0, NFPROTO_IPV4);
if (!h) die(h);
status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
if (status < 0) die(h);
do{
i++;
status = ipq_read(h, buf, BUFSIZE, 0);
if (status < 0) die(h);
switch (ipq_message_type(buf)) {
case NLMSG_ERROR:
fprintf(stderr, "Received error message %d\n",
ipq_get_msgerr(buf));
break;
case IPQM_PACKET:
{
ipq_packet_msg_t *m = ipq_get_packet(buf);
printf("\nReceived Packet");
/****YOUR CODE TO MODIFY PACKET GOES HERE****/
status = ipq_set_verdict(h, m->packet_id, NF_ACCEPT, 0, NULL);
if (status < 0) die(h);
break;
}
default:
fprintf(stderr, "Unknown message type!\n");
break;
}
} while (1);
ipq_destroy_handle(h);
return 0;
}
相關問題
- 1. 修改數據包的netfilter
- 2. 在netfilter模塊中重新注入修改的數據包
- 3. 使用netfilter隊列修改數據包?
- 4. Linux傳入/傳出數據包修改模塊
- 5. 在linux網關修改http數據包
- 6. 本地處理的數據包上的netfilter事件(netfilter C內核模塊代碼)
- 7. 如何使用netfilter捕獲數據包?
- 8. 如何使用netfilter內核模塊從sk_buff讀取數據?
- 9. iptables的netfilter的複製數據包
- 10. 用於Linux的Oracle模塊
- 11. 關於修改模塊的建議
- 12. 修改Webform模塊
- 13. 修改子模塊
- 14. 關於Linux模塊printk的
- 15. 如何使用可加載模塊修改Linux網絡堆棧?
- 16. LSP數據包修改
- 17. DPDK - 數據包修改
- 18. 用於修改圖表數據的VBA
- 19. 用於XML數據修改的Excel宏
- 20. 如何破解Linux Netfilter-iptable?
- 21. 修改linux內核中的現有模塊
- 22. 如何更改以太網數據包(來自NIC的數據包)?我可以使用Netfilter掛鉤嗎?
- 23. 如何使用winpcap修改數據包
- 24. 使用netfilter隊列時數據包頭的格式是什麼?
- 25. 從netfilter接收用戶空間中的數據包
- 26. 在NetFilter中使用NF_QUEUE排隊網絡數據包的示例
- 27. 關於linux內核模塊
- 28. 修改開發模塊
- 29. 修改Joomla html5模塊chrome
- 30. PHP模塊修改$ _POST,$ _FILES
你有什麼試過嗎? (http://mattgemmell.com/2008/12/08/what-have-you-tried/) – 2012-04-29 13:47:28
我什麼也沒試,因爲我找不到東西 – user1262425 2012-04-29 15:18:58