summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libnfnetlink.c19
-rw-r--r--libnfnetlink.h4
2 files changed, 23 insertions, 0 deletions
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 *);