Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * T.c
- *
- * compile: gcc -Wall T2.c -o T2 -lipq
- */
- #include <netinet/in.h>
- #include <libipq.h>
- #include <linux/netfilter.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <netinet/ip.h>
- #include <netinet/udp.h>
- #include <netinet/tcp.h>
- #define BUFSIZE 131072
- static void die(struct ipq_handle *h) {
- ipq_perror("passer");
- ipq_destroy_handle(h);
- }
- void start_packet_engine() {
- int status;
- unsigned char buf[BUFSIZE];
- struct ipq_handle *h;
- printf("\nLaukiame paketu\n");
- h = ipq_create_handle(0, PF_INET);
- if (!h)
- die(h);
- status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
- if (status < 0)
- die(h);
- do {
- 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);
- struct iphdr *iph = ((struct iphdr *)m->payload);
- struct tcphdr *tcp = (struct tcphdr *)(m->payload + (iph->ihl << 2));
- struct udphdr *udp = (struct udphdr *) (m->payload + (iph->ihl << 2));
- int unsigned payload_offset = ((iph->ihl << 2) + (tcp->doff << 2));
- int unsigned payload_length = (unsigned int) ntohs(iph->tot_len) -
- payload_offset;
- //unsigned char data[2]={0x00,0x00};
- unsigned char data[4]={0x00,0x00,0x01,0xb3};
- int i = 0;
- while(m->data_len > 100) {
- if (m->payload[i] != 0x00) {
- i++;
- }
- else {
- if (memcmp(&m->payload[i],data,sizeof(data)) == 0) {
- printf("I frame");
- break; }
- }
- }
- status = ipq_set_verdict(h, m->packet_id,NF_ACCEPT, 0, NULL);
- break;
- }
- }
- }
- while (1);
- printf("Engine Stopped...\n");
- ipq_destroy_handle(h);
- }
- int main() {
- start_packet_engine();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement