- 论坛徽章:
- 0
|
回复 #26 Godbach 的帖子
什么叫meta data?
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <signal.h>
- #include <netinet/ip_icmp.h>
- #include <netinet/ip.h>
- #include <arpa/inet.h>
- #include "libipq.h"
- #define ETH_HDRLEN 14
- #define NF_ACCEPT 1
- #define NF_DROP 0
- struct ipq_handle *h = NULL;
- static void sig_int(int signo)
- {
- ipq_destroy_handle(h);
- printf("Exit: %s\n", ipq_errstr());
- exit(0);
- }
- int main(void)
- {
- unsigned char buf[1024];
- /* creat handle*/
- h = ipq_create_handle(0, PF_INET);
- if(h == NULL){
- printf("%s\n", ipq_errstr());
- return 0;
- }
- printf("ipq_creat_handle success!\n");
- /*set mode*/
- unsigned char mode = IPQ_COPY_PACKET;
- int range = sizeof(buf);
- int ret = ipq_set_mode(h, mode, range);
- printf("ipq_set_mode: send bytes =%d, range=%d\n", ret, range);
-
- /*register signal handler*/
- signal(SIGINT, sig_int);
- /*read packet from kernel*/
- int status;
- struct nlmsghdr *nlh;
- ipq_packet_msg_t *ipq_packet;
-
- while(1){
- status = ipq_read(h, buf, sizeof(buf));
- if(status > sizeof(struct nlmsghdr))
- {
- nlh = (struct nlmsghdr *)buf;
- ipq_packet = ipq_get_packet(buf);
- printf("recv bytes =%d, nlmsg_len=%d, indev=%s, datalen=%d, packet_id=%x\n", status, nlh->nlmsg_len,
- ipq_packet->indev_name, ipq_packet->data_len, ipq_packet->packet_id);
- unsigned char payload[1050];
- memset(payload, 0x00, sizeof(payload));
- memcpy(payload + ETH_HDRLEN, ipq_packet->payload, ipq_packet->data_len);
- printf("\n");
- struct iphdr * hdr =(struct iphdr *) payload;
- ret = ipq_set_verdict(h, ipq_packet->packet_id, NF_ACCEPT,ipq_packet->data_len,payload + ETH_HDRLEN);
- printf("TCP Accepted!\n");
- }
- }
- return 0;
- }
复制代码
基本就是你的代码,但是就是打开不了网页... |
|