/* * T.c * * compile: gcc -Wall T.c -o T -lipq */ #include #include #include #include #include #include #include #include #include #include #define BUFSIZE 65536 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("\nWaiting for packets\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); 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; }