From 721a93769a15c0f579a389ad58d82d14d13f7f93 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Wed, 9 Apr 2008 12:09:04 +0000 Subject: add nfct_send --- configure.in | 2 +- .../libnetfilter_conntrack.h | 4 +++ src/conntrack/api.c | 33 +++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 3640e88..481b6b0 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ AC_INIT AC_CANONICAL_SYSTEM -AM_INIT_AUTOMAKE(libnetfilter_conntrack, 0.0.89) +AM_INIT_AUTOMAKE(libnetfilter_conntrack, 0.0.90) AC_PROG_CC AM_PROG_LIBTOOL diff --git a/include/libnetfilter_conntrack/libnetfilter_conntrack.h b/include/libnetfilter_conntrack/libnetfilter_conntrack.h index 27c3cf0..644806d 100644 --- a/include/libnetfilter_conntrack/libnetfilter_conntrack.h +++ b/include/libnetfilter_conntrack/libnetfilter_conntrack.h @@ -279,6 +279,10 @@ extern int nfct_query(struct nfct_handle *h, const enum nf_conntrack_query query, const void *data); +extern int nfct_send(struct nfct_handle *h, + const enum nf_conntrack_query query, + const void *data); + extern int nfct_catch(struct nfct_handle *h); /* low level API: netlink functions */ diff --git a/src/conntrack/api.c b/src/conntrack/api.c index f2f3cb5..04f78ed 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -548,7 +548,7 @@ int nfct_parse_conntrack(enum nf_conntrack_msg_type type, } /** - * nfct_query - send a query to ctnetlin + * nfct_query - send a query to ctnetlink and handle the reply * @h: library handler * @qt: query type * @data: data required to send the query @@ -573,6 +573,37 @@ int nfct_query(struct nfct_handle *h, return nfnl_query(h->nfnlh, &req->nlh); } +/** + * nfct_send - send a query to ctnetlink + * @h: library handler + * @qt: query type + * @data: data required to send the query + * + * Like nfct_query but we do not wait for the reply from ctnetlink. + * You can use nfct_send() and nfct_catch() to emulate nfct_query(). + * This is particularly useful when the socket is non-blocking. + * + * On error, -1 is returned and errno is explicitely set. On success, 0 + * is returned. + */ +int nfct_send(struct nfct_handle *h, + const enum nf_conntrack_query qt, + const void *data) +{ + size_t size = 4096; /* enough for now */ + char buffer[4096]; + struct nfnlhdr *req = (struct nfnlhdr *) buffer; + + assert(h != NULL); + assert(data != NULL); + + if (nfct_build_query(h->nfnlssh_ct, qt, data, req, size) == -1) + return -1; + + return nfnl_send(h->nfnlh, &req->nlh); +} + + /** * nfct_catch - catch events * @h: library handler -- cgit v1.2.3