MCPcopy Create free account
hub / github.com/ElementsProject/lightning / fdpass_send

Function fdpass_send

ccan/ccan/fdpass/fdpass.c:7–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <string.h>
6
7bool fdpass_send(int sockout, int fd)
8{
9 /* From the cmsg(3) manpage: */
10 struct msghdr msg = { 0 };
11 struct cmsghdr *cmsg;
12 struct iovec iov;
13 char c = 0;
14 union { /* Ancillary data buffer, wrapped in a union
15 in order to ensure it is suitably aligned */
16 char buf[CMSG_SPACE(sizeof(fd))];
17 struct cmsghdr align;
18 } u;
19
20 msg.msg_control = u.buf;
21 msg.msg_controllen = sizeof(u.buf);
22 memset(&u, 0, sizeof(u));
23 cmsg = CMSG_FIRSTHDR(&msg);
24 cmsg->cmsg_level = SOL_SOCKET;
25 cmsg->cmsg_type = SCM_RIGHTS;
26 cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
27 memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
28
29 msg.msg_name = NULL;
30 msg.msg_namelen = 0;
31 msg.msg_iov = &iov;
32 msg.msg_iovlen = 1;
33 msg.msg_flags = 0;
34
35 /* Keith Packard reports that 0-length sends don't work, so we
36 * always send 1 byte. */
37 iov.iov_base = &c;
38 iov.iov_len = 1;
39
40 return sendmsg(sockout, &msg, 0) == 1;
41}
42
43int fdpass_recv(int sockin)
44{

Callers 5

do_fd_sendFunction · 0.85
parentFunction · 0.85
status_send_fdFunction · 0.85
daemon_conn_sync_flushFunction · 0.85

Calls

no outgoing calls

Tested by 1

parentFunction · 0.68