summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-08-05 22:00:12 +0200
committerThomas Haller <thaller@redhat.com>2022-08-09 08:02:39 +0200
commit6e7d8f0335e36c0cccb34d915a67532fd9df92ca (patch)
treecfb59291fa4b5c75ef5683560375ea17977dd372
parentc74c783c2892ab0e73876751de71bf2ba9c28a72 (diff)
downloadNetworkManager-6e7d8f0335e36c0cccb34d915a67532fd9df92ca.tar.gz
platform/netlink: add nlmsg_undata() helper
-rw-r--r--src/libnm-platform/nm-netlink.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libnm-platform/nm-netlink.h b/src/libnm-platform/nm-netlink.h
index d21abb5002..1b4267c517 100644
--- a/src/libnm-platform/nm-netlink.h
+++ b/src/libnm-platform/nm-netlink.h
@@ -442,16 +442,23 @@ void nlmsg_set_creds(struct nl_msg *msg, struct ucred *creds);
NM_AUTO_DEFINE_FCN0(struct nl_msg *, _nm_auto_nl_msg_cleanup, nlmsg_free);
#define nm_auto_nlmsg nm_auto(_nm_auto_nl_msg_cleanup)
+static inline const struct nlmsghdr *
+nlmsg_undata(const void *data)
+{
+ /* from the data, get back the header. It's the inverse of nlmsg_data(). */
+ return (void *) (((unsigned char *) data) - NLMSG_HDRLEN);
+}
+
static inline void *
nlmsg_data(const struct nlmsghdr *nlh)
{
- return (unsigned char *) nlh + NLMSG_HDRLEN;
+ return ((unsigned char *) nlh) + NLMSG_HDRLEN;
}
static inline void *
nlmsg_tail(const struct nlmsghdr *nlh)
{
- return (unsigned char *) nlh + NLMSG_ALIGN(nlh->nlmsg_len);
+ return ((unsigned char *) nlh) + NLMSG_ALIGN(nlh->nlmsg_len);
}
struct nlmsghdr *nlmsg_hdr(const struct nl_msg *n);