Merge pull request #15570 from poettering/cmsg-find

CMSG_FIND_DATA() and cmsg_find() work
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-04-24 07:45:07 +02:00
committed by GitHub
10 changed files with 40 additions and 95 deletions
+2 -11
View File
@@ -887,7 +887,7 @@ ssize_t receive_one_fd_iov(
.msg_iov = iov,
.msg_iovlen = iovlen,
};
struct cmsghdr *cmsg, *found = NULL;
struct cmsghdr *found;
ssize_t k;
assert(transport_fd >= 0);
@@ -905,16 +905,7 @@ ssize_t receive_one_fd_iov(
if (k < 0)
return k;
CMSG_FOREACH(cmsg, &mh) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
assert(!found);
found = cmsg;
break;
}
}
found = cmsg_find(&mh, SOL_SOCKET, SCM_RIGHTS, CMSG_LEN(sizeof(int)));
if (!found) {
cmsg_close_all(&mh);
+8
View File
@@ -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