From a8e6e8ae4ba2fdd6afb640623f140c102a70a3e4 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: Wed, 27 Jul 2005 19:21:54 +0000 Subject: add nfnl_parse_hdr() function --- libnfnetlink.c | 19 +++++++++++++++++++ libnfnetlink.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/libnfnetlink.c b/libnfnetlink.c index f0997fd..80cb0c4 100644 --- a/libnfnetlink.c +++ b/libnfnetlink.c @@ -186,6 +186,25 @@ void nfnl_fill_hdr(struct nfnl_handle *nfnlh, nfg->res_id = htons(res_id); } +struct nfattr * +nfnl_parse_hdr(struct nfnl_handle *nfnlh, const struct nlmsghdr *nlh, + struct nfgenmsg **genmsg) +{ + if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct nfgenmsg))) + return NULL; + + if (nlh->nlmsg_len == NLMSG_LENGTH(sizeof(struct nfgenmsg))) { + if (genmsg) + *genmsg = (struct nfgenmsg *)((void *)nlh+sizeof(nlh)); + return NULL; + } + + if (genmsg) + *genmsg = (struct nfgenmsg *)((void *)nlh + sizeof(nlh)); + + return ((void *)nlh + NLMSG_LENGTH(sizeof(struct nfgenmsg))); +} + /** * nfnl_listen: listen for one or more netlink messages * diff --git a/libnfnetlink.h b/libnfnetlink.h index 6ffd644..137c62e 100644 --- a/libnfnetlink.h +++ b/libnfnetlink.h @@ -38,6 +38,10 @@ extern void nfnl_fill_hdr(struct nfnl_handle *, struct nlmsghdr *, unsigned int, u_int8_t, u_int16_t, u_int16_t, u_int16_t); +extern struct nfattr *nfnl_parse_hdr(struct nfnl_handle *nfnlh, + const struct nlmsghdr *nlh, + struct nfgenmsg **genmsg); + extern int nfnl_listen(struct nfnl_handle *, int (*)(struct sockaddr_nl *, struct nlmsghdr *, void *), void *); -- cgit v1.2.3