From: Patrick McHardy <kaber@trash.net>
To: Essien Ita Essien <essiene@datavibe.net>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: compiling libipq example
Date: Thu, 03 Mar 2005 13:54:31 +0100 [thread overview]
Message-ID: <42270907.9070200@trash.net> (raw)
In-Reply-To: <421EE3A0.7000804@datavibe.net>
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
Essien Ita Essien wrote:
> Hi,
>
> I'm trying to follow the tutorial in the libipq man page, with just a
> little modification, and i get a compile error when i try to access the
> ipq_packet_msg_t structure. I've checked where ipq_packet_msg_t is
> defined, and found it in <linux/netfilter_ipv4/ip_queue.h>, which i've
> found is conditionally included in <libipq.h> already. I even tried
> including straight into the program.
>
> Any ideas what i'm doing wrong?
I've used the attached code for testing some time ago, maybe it helps.
[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 158 bytes --]
CC = gcc
LD = ld
CFLAGS = -Wall -O2
LDFLAGS = -lipq
all: nfqtest
clean:
rm -f nfqtest nfqtest.o
nfqtest: nfqtest.o
$(CC) nfqtest.o -o nfqtest $(LDFLAGS)
[-- Attachment #3: nfqtest.c --]
[-- Type: text/x-csrc, Size: 1771 bytes --]
/* just some testing code for the netfilter packet queuing to userspace
(C) 2000 by Harald Welte <laforge@sunbeam.franken.de>
This code is licensed under GPL conditions
*/
#include <stdio.h>
#include <stdlib.h>
#include <libipq/libipq.h>
#include <linux/netfilter.h>
#include <sys/socket.h>
#include <sys/un.h>
#define IPQ_BUF_SIZE 100000
static struct ipq_handle *qh;
static int handle_packet(ipq_packet_msg_t *pkt)
{
int ret;
printf("id: %lu, mark: %lu, timestamp: %ld %ld , indev: %s, datalen: %u\n",
pkt->packet_id, pkt->mark, pkt->timestamp_sec, pkt->timestamp_usec,
pkt->indev_name, (unsigned int)pkt->data_len);
ret = ipq_set_verdict(qh, pkt->packet_id, NF_ACCEPT, pkt->data_len, pkt->payload);
if (ret < 0) {
printf("error setting verdict\n");
ipq_perror(NULL);
}
return ret;
}
int main(int argc, char **argv)
{
ssize_t len;
unsigned char *buf;
qh = ipq_create_handle(0, PF_INET);
if (!qh) {
printf("can't create netlink socket\n");
ipq_perror(NULL);
exit(1);
}
if (ipq_set_mode(qh, IPQ_COPY_PACKET, 0xFFFF) < 0) {
printf("can't set netlink mode\n");
ipq_perror(NULL);
exit(2);
}
buf = malloc(IPQ_BUF_SIZE);
while (1) {
int ptype, error;
ipq_packet_msg_t *packet;
len = ipq_read(qh, buf, IPQ_BUF_SIZE, 0);
if (len < 0) {
printf("len < 0\n");
break;
} else if (len == 0) {
printf("timeout exceeded\n");
continue;
}
ptype = ipq_message_type(buf);
packet = ipq_get_packet(buf);
printf("received packet, length=%d, type=%d\n", (int)len, ptype);
switch (ptype) {
case NLMSG_ERROR:
error = -ipq_get_msgerr(buf);
printf("NLMSG_ERROR: %d\n", error);
exit(3);
break;
case IPQM_PACKET:
handle_packet(packet);
break;
}
}
ipq_perror(NULL);
exit(0);
}
next prev parent reply other threads:[~2005-03-03 12:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-25 8:36 compiling libipq example Essien Ita Essien
2005-03-03 12:54 ` Patrick McHardy [this message]
2005-03-03 15:28 ` Essien Ita Essien
2005-03-03 13:17 ` Jonas Berlin
2005-03-03 15:26 ` Essien Ita Essien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42270907.9070200@trash.net \
--to=kaber@trash.net \
--cc=essiene@datavibe.net \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.