7 /* send file descriptor
9 /* #include <iostuff.h>
11 /* int stream_send_fd(fd, sendfd)
15 /* stream_send_fd() sends a file descriptor over the specified
22 /* Another file descriptor.
24 /* stream_send_fd() returns -1 upon failure.
28 /* The Secure Mailer license must be distributed with this software.
31 /* IBM T.J. Watson Research
33 /* Yorktown Heights, NY 10598, USA
38 #include <sys_defs.h> /* includes <sys/types.h> */
40 #ifdef STREAM_CONNECTIONS
50 /* Utility library. */
55 /* stream_send_fd - send file descriptor */
57 int stream_send_fd(int fd
, int sendfd
)
59 #ifdef STREAM_CONNECTIONS
60 const char *myname
= "stream_send_fd";
62 if (ioctl(fd
, I_SENDFD
, sendfd
) < 0)
63 msg_fatal("%s: send file descriptor %d: %m", myname
, sendfd
);
66 msg_fatal("stream connections are not implemented");
73 * Proof-of-concept program. Open a file and send the descriptor, presumably
74 * to the stream_recv_fd test program.
83 int main(int argc
, char **argv
)
92 || (endpoint
= split_at(transport
= argv
[1], ':')) == 0
93 || *endpoint
== 0 || *transport
== 0)
94 msg_fatal("usage: %s transport:endpoint file...", argv
[0]);
96 if (strcmp(transport
, "stream") == 0) {
97 server_sock
= stream_connect(endpoint
, BLOCKING
, 0);
99 msg_fatal("invalid transport name: %s", transport
);
102 msg_fatal("connect %s:%s: %m", transport
, endpoint
);
105 while ((path
= *argv
++) != 0) {
106 if ((client_fd
= open(path
, O_RDONLY
, 0)) < 0)
107 msg_fatal("open %s: %m", path
);
108 msg_info("path=%s client_fd=%d", path
, client_fd
);
109 if (stream_send_fd(server_sock
, client_fd
) < 0)
110 msg_fatal("send file descriptor: %m");
111 if (close(client_fd
) != 0)
112 msg_fatal("close(%d): %m", client_fd
);