5
/* send file descriptor
7
/* #include <iostuff.h>
9
/* int stream_send_fd(fd, sendfd)
13
/* stream_send_fd() sends a file descriptor over the specified
20
/* Another file descriptor.
22
/* stream_send_fd() returns -1 upon failure.
26
/* The Secure Mailer license must be distributed with this software.
29
/* IBM T.J. Watson Research
31
/* Yorktown Heights, NY 10598, USA
36
#include <sys_defs.h> /* includes <sys/types.h> */
38
#ifdef STREAM_CONNECTIONS
48
/* Utility library. */
53
/* stream_send_fd - send file descriptor */
55
int stream_send_fd(int fd, int sendfd)
57
char *myname = "stream_send_fd";
59
#ifdef STREAM_CONNECTIONS
60
if (ioctl(fd, I_SENDFD, sendfd) < 0)
61
msg_fatal("%s: send file descriptor: %m", myname);
63
msg_fatal("stream connections are not implemented");
70
* Proof-of-concept program. Open a file and send the descriptor, presumably
71
* to the stream_recv_fd test program.
78
int main(int argc, char **argv)
87
|| (endpoint = split_at(transport = argv[1], ':')) == 0
88
|| *endpoint == 0 || *transport == 0)
89
msg_fatal("usage: %s transport:endpoint file...", argv[0]);
91
if (strcmp(transport, "stream") == 0) {
92
server_sock = stream_connect(endpoint, BLOCKING, 0);
94
msg_fatal("invalid transport name: %s", transport);
97
msg_fatal("connect %s:%s: %m", transport, endpoint);
100
while ((path = *argv++) != 0) {
101
if ((client_fd = open(path, O_RDONLY, 0)) < 0)
102
msg_fatal("open %s: %m", path);
103
msg_info("path=%s client_fd=%d", path, client_fd);
104
if (stream_send_fd(server_sock, client_fd) < 0)
105
msg_fatal("send file descriptor: %m");
106
if (close(client_fd) != 0)
107
msg_fatal("close(%d): %m", client_fd);