summaryrefslogtreecommitdiff
path: root/src/basic/socket-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-17 11:52:48 +0200
committerLennart Poettering <lennart@poettering.net>2020-04-23 19:41:15 +0200
commit371d72e05b7e2c2b7850cb04d8d4c18be1e60421 (patch)
treec6b0f467bca7db6d1c5f2d2262199ca2256a8f01 /src/basic/socket-util.h
parentdac556fa7ba19846f787e560e7de8958891b6754 (diff)
downloadsystemd-371d72e05b7e2c2b7850cb04d8d4c18be1e60421.tar.gz
socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA around cmsg_find()
let's take this once step further, and add type-safety to cmsg_find(), and imply the CMSG_DATA() macro for finding the cmsg payload.
Diffstat (limited to 'src/basic/socket-util.h')
-rw-r--r--src/basic/socket-util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index 95643135df..fba4efef81 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -158,6 +158,14 @@ int flush_accept(int fd);
struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t length);
+/* Type-safe, dereferencing version of cmsg_find() */
+#define CMSG_FIND_DATA(mh, level, type, ctype) \
+ ({ \
+ struct cmsghdr *_found; \
+ _found = cmsg_find(mh, level, type, CMSG_LEN(sizeof(ctype))); \
+ (ctype*) (_found ? CMSG_DATA(_found) : NULL); \
+ })
+
/*
* Certain hardware address types (e.g Infiniband) do not fit into sll_addr
* (8 bytes) and run over the structure. This macro returns the correct size that