From 9b5887192ed5c9bad4f2d2d270e88c49ef606b92 Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org" Date: Mon, 8 Aug 2005 17:08:03 +0000 Subject: - some more work on libipulog compat API [almost finished] - improt ulog_test.c from libipulog in order to test libipulog compat API --- src/libipulog_compat.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/libipulog_compat.c b/src/libipulog_compat.c index d981e94..a0675ec 100644 --- a/src/libipulog_compat.c +++ b/src/libipulog_compat.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,7 @@ u_int32_t ipulog_group2gmask(u_int32_t group) struct ipulog_handle *ipulog_create_handle(u_int32_t gmask, u_int32_t rcvbufsize) { + int rv; struct ipulog_handle *h; unsigned int group = gmask2group(gmask); @@ -98,7 +100,9 @@ struct ipulog_handle *ipulog_create_handle(u_int32_t gmask, if (!h->nfulh) goto out_free; - if (nfulnl_bind_pf(h->nfulh, AF_INET) < 0) + /* bind_pf returns EEXIST if we are already registered */ + rv = nfulnl_bind_pf(h->nfulh, AF_INET); + if (rv < 0 && rv != -EEXIST) goto out_free; h->nful_gh = nfulnl_bind_group(h->nfulh, group); @@ -128,10 +132,11 @@ ulog_packet_msg_t *ipulog_get_packet(struct ipulog_handle *h, struct nfattr *tb[NFULA_MAX]; struct nfulnl_msg_packet_hdr *hdr; - if (!h->last_nlh) + if (!h->last_nlh) { + printf("first\n"); nlh = nfnl_get_msg_first(nfulnl_nfnlh(h->nfulh), buf, len); - else { -next_msg: + }else { +next_msg: printf("next\n"); nlh = nfnl_get_msg_next(nfulnl_nfnlh(h->nfulh), buf, len); } h->last_nlh = nlh; @@ -139,7 +144,8 @@ next_msg: if (!nlh) return NULL; - nfnl_parse_attr(tb, NFULA_MAX, NFM_NFA(nlh), NFM_PAYLOAD(nlh)); + nfnl_parse_attr(tb, NFULA_MAX, NFM_NFA(NLMSG_DATA(nlh)), + NFM_PAYLOAD(nlh)); if (!tb[NFULA_PACKET_HDR-1]) goto next_msg; @@ -199,7 +205,9 @@ next_msg: ssize_t ipulog_read(struct ipulog_handle *h, unsigned char *buf, size_t len, int timeout) { - //return nfnl_listen(); + /* 'timeout' was never implemented in the original libipulog, + * so we don't bother emulating it */ + return nfnl_recv(nfulnl_nfnlh(h->nfulh), buf, len); } /* print a human readable description of the last error to stderr */ -- cgit v1.2.3