Skip to contentSkip to conversation

anyone can help me with ipqdemo?

DISCUSSION Fangweiwei 2 participants 2 messages Dec 1, 2003 netfilter

lore
Share & tools
lore

Fangweiwei

author
#0 lore raw

netfilter-devel,hi!
I have download the ipqdemo and run it in the console as root , but the cursor just wait there,and I don't think it works.I am a new user ,and I strive to make it work well, but I failed.Can you help me?
the source code is:
/*
* ipqdemo.c by Alexander Demenshin <[email protected]>
* version 0.0a (very, very alpha :))
*
* IPQ usage demonstration (very, very basic :)
*
* What it does? Nothing serious - only accept packets that are coming
* from QUEUE target(s) and prints them out (not completely for now).
* At least it may be usefult for beginners who have no where to start
* playing with ip_queue :)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4/ip_queue.h>
#include <linux/ip.h>
#include "include/libipq/libipq.h"
/* Normally, we should not expect that packets will be so big,
even including metadata, but who knows? :)
*/
#define MAX_PACKET_LEN 8192
void main(int argc, char **argv)
{
struct ipq_handle *qh;
struct ipq_packet_msg *qpkt;
struct iphdr *iph;
unsigned char buff[sizeof *qpkt + MAX_PACKET_LEN];
int type;
int len;
/* Init first (flags are not implemented; yet) */
if ((qh = ipq_create_handle(0)) == NULL) {
/* Run away... */
ipq_perror("create_handle()");
exit(1);
}

/* We would like to receive not only metadata... */ if (ipq_set_mode(qh, IPQ_COPY_PACKET, MAX_PACKET_LEN) < 0) {
ipq_perror("set_mode()");
goto cleanup;
}

/*
* Now real fun begins... Just stay in loop, read packets,
* accept them if they are IP.
*/
while (1) {
len = ipq_read(qh, buff, sizeof buff, 0);
if (len == 0) {
fprintf(stderr, "read(): Zero length packet; ingnoring\n"); continue;
}
if (len < 0) {
ipq_perror("read()");
goto cleanup;
}
qpkt = ipq_get_packet(buff);
iph = (struct iphdr *)qpkt->payload;
/* If packet type from kernel is not known to us,
* just ignore it (but notify user)
*/
if ((type = ipq_message_type(buff)) != IPQM_PACKET) {
fprintf(stderr, "read(): Unknown message type %u\n",

    type);

continue;
}
/* Now we know that it is IPv4 packet... So, accept it,
* but print out some use(ful|less) info first :)
* The reason why I use stderr here is to avoid output
* delays due to buffering on stdout. Yes, I am lazy :)
*/
fprintf(stderr, "%08X %08X %04X [%-6s=>%6s] (%4u/%4u) %08X => %08X\n",
qpkt->packet_id, qpkt->mark, qpkt->hook, qpkt->indev_name, qpkt->outdev_name,
qpkt->data_len,
iph->ihl << 2,
ntohl(iph->saddr), ntohl(iph->daddr)
);
/* Just accept, nothing more... */
if (ipq_set_verdict(qh, qpkt->packet_id, NF_ACCEPT, 0, NULL) < 0) {
ipq_perror("set_verdict(): Oops!");
goto cleanup;
}
}
cleanup:
ipq_destroy_handle(qh);
}

Regards

        Fangweiwei
        [email protected]
         2003-12-01

#1 lore raw
Quoted 3 lines · Fangweiwei

I have download the ipqdemo and run it in the console as root , but
the cursor just wait there,and I don't think it works.I am a new user ,and I strive to make it work well, but I failed.Can you help me?

Yave you instructed iptables to QUEUE some packets?

If nothing is targeted to QUEUE nothing will get to the application..

Regards
Henrik