Linux Netfilter discussions
 help / color / mirror / Atom feed
* NFQUEUE hello world-style program
@ 2008-07-03 20:07 Simon Perreault
  2008-07-04  9:26 ` Eric Leblond
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Perreault @ 2008-07-03 20:07 UTC (permalink / raw)
  To: netfilter

Hello,

I'm trying to write a hello world-style program using NFQUEUE. It hangs in the 
select() call on the nfq file descriptor even though I can see 
with "iptables -L -n -v" that there are packets that match the rule.

Here's my iptables rule:

# iptables -A INPUT -p udp --dport 12345 -j NFQUEUE --queue-num=0

I generate packets thusly:

# echo "hello" | nc -u localhost 12345

Here's my C code:

=======================================================
#include <libnetfilter_queue/libnetfilter_queue.h>

#include <stdio.h>

int cb( struct nfq_q_handle* q, struct nfgenmsg *nfmsg,
        struct nfq_data *nfad, void *data )
{
    char* payload;
    printf( "received %d bytes\n", nfq_get_payload(nfad, &payload) );
    return 0;
}

int main()
{
    struct nfq_handle* h = nfq_open();
    struct nfq_q_handle* q = nfq_create_queue( h, 0, cb, 0 );
    int fd = nfq_fd(h);

    while (1) {
        fd_set readfds;
        FD_ZERO(&readfds);
        FD_SET(fd, &readfds);
        select( fd + 1, &readfds, 0, 0, 0 );

        char buf[8192];
        ssize_t size = recv( fd, buf, sizeof(buf), 0 );

        nfq_handle_packet( h, buf, size );
    }

    return 0;
}
=======================================================

Any idea what might be missing?

Thanks,
Simon

-- 
Please try Numb, a STUN/TURN server implementation.
Free access at http://numb.viagenie.ca/.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-07-04 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-03 20:07 NFQUEUE hello world-style program Simon Perreault
2008-07-04  9:26 ` Eric Leblond
2008-07-04 12:28   ` Simon Perreault
2008-07-04 14:08     ` Eric Leblond
2008-07-04 12:57   ` Simon Perreault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox