From ce202ac843cd8cae275089ba623774a1adb1b008 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 5 Aug 2014 22:37:31 +0200 Subject: [PATCH] monitor: Add helper functions for parsing-only netlink monitor --- monitor/nlmon.c | 32 ++++++++++++++++++++++++++++++++ monitor/nlmon.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/monitor/nlmon.c b/monitor/nlmon.c index fb0b10b8..cd62407c 100644 --- a/monitor/nlmon.c +++ b/monitor/nlmon.c @@ -913,6 +913,38 @@ static void nlmon_message(struct nlmon *nlmon, const struct nlmsghdr *nlmsg) } } +struct nlmon *nlmon_create(void) +{ + struct nlmon *nlmon; + + nlmon = l_new(struct nlmon, 1); + + nlmon->id = 27; + nlmon->req_list = l_queue_new(); + + return nlmon; +} + +void nlmon_destroy(struct nlmon *nlmon) +{ + if (!nlmon) + return; + + l_queue_destroy(nlmon->req_list, nlmon_req_free); + + l_free(nlmon); +} + +void nlmon_print(struct nlmon *nlmon, const void *data, uint32_t size) +{ + const struct nlmsghdr *nlmsg; + + for (nlmsg = data; NLMSG_OK(nlmsg, size); + nlmsg = NLMSG_NEXT(nlmsg, size)) { + nlmon_message(nlmon, nlmsg); + } +} + static bool nlmon_receive(struct l_io *io, void *user_data) { struct nlmon *nlmon = user_data; diff --git a/monitor/nlmon.h b/monitor/nlmon.h index 0dd2d63b..bb372fd3 100644 --- a/monitor/nlmon.h +++ b/monitor/nlmon.h @@ -26,3 +26,7 @@ struct nlmon; struct nlmon *nlmon_open(const char *ifname, uint16_t id); void nlmon_close(struct nlmon *nlmon); + +struct nlmon *nlmon_create(void); +void nlmon_destroy(struct nlmon *nlmon); +void nlmon_print(struct nlmon *nlmon, const void *data, uint32_t size);