37 #include <sys/socket.h>
55 #ifdef CANT_USE_SEND_RECV_MSG
56 const char *myname =
"unix_send_fd";
58 msg_warn(
"%s: your system has no support for file descriptor passing",
70 #if defined(CMSG_SPACE) && !defined(NO_MSGHDR_MSG_CONTROL)
72 struct cmsghdr just_for_alignment;
73 char control[CMSG_SPACE(
sizeof(sendfd))];
75 struct cmsghdr *cmptr;
77 memset((
void *) &msg, 0,
sizeof(msg));
78 msg.msg_control = control_un.control;
80 msg.msg_controllen = CMSG_LEN(
sizeof(sendfd));
82 msg.msg_controllen =
sizeof(control_un.control);
84 cmptr = CMSG_FIRSTHDR(&msg);
85 cmptr->cmsg_len = CMSG_LEN(
sizeof(sendfd));
86 cmptr->cmsg_level = SOL_SOCKET;
87 cmptr->cmsg_type = SCM_RIGHTS;
88 *(
int *) CMSG_DATA(cmptr) = sendfd;
90 msg.msg_accrights = (
char *) &sendfd;
91 msg.msg_accrightslen =
sizeof(sendfd);
131 if (sendmsg(fd, &msg, 0) >= 0)
135 msg_info(
"sendmsg error (%m). Trying CMSG_LEN workaround.");
157 int main(
int argc,
char **argv)
168 || (endpoint =
split_at(transport = argv[1],
':')) == 0
169 || *endpoint == 0 || *transport == 0)
170 msg_fatal(
"usage: %s transport:endpoint file...", argv[0]);
172 if (strcmp(transport,
"unix") == 0) {
175 msg_fatal(
"invalid transport name: %s", transport);
178 msg_fatal(
"connect %s:%s: %m", transport, endpoint);
181 while ((path = *argv++) != 0) {
182 if ((client_fd = open(path, O_RDONLY, 0)) < 0)
184 msg_info(
"path=%s fd=%d", path, client_fd);
187 if (close(client_fd) != 0)
int unix_send_fd(int fd, int sendfd)
int main(int argc, char **argv)
int unix_connect(const char *, int, int)
void msg_warn(const char *fmt,...)
NORETURN msg_fatal(const char *fmt,...)
char * split_at(char *string, int delimiter)
#define UNIX_PASS_FD_FIX_CMSG_LEN
void msg_info(const char *fmt,...)