… | |
… | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
25 | |
25 | |
26 | #include "../config.h" |
26 | #include "../config.h" |
27 | |
27 | |
|
|
28 | #include <cstddef> // needed by broken bsds for NULL used in sys/uio.h |
|
|
29 | |
28 | #include <sys/uio.h> |
30 | #include <sys/uio.h> |
29 | #include <sys/types.h> |
31 | #include <sys/types.h> |
30 | #include <sys/socket.h> |
32 | #include <sys/socket.h> |
31 | |
33 | |
32 | #include "libptytty.h" |
34 | #include "libptytty.h" |
33 | |
35 | |
34 | #ifndef CMSG_LEN // CMSG_SPACe && CMSG_LEN are rfc2292 extensions to unix |
36 | #ifndef CMSG_LEN // CMSG_SPACe && CMSG_LEN are rfc2292 extensions to unix |
35 | # define CMSG_LEN(len) (sizeof (cmsghdr) + len) |
37 | # define CMSG_LEN(len) (sizeof (cmsghdr) + len) |
36 | #endif |
38 | #endif |
37 | |
39 | |
38 | int |
40 | bool |
39 | ptytty::send_fd (int socket, int fd) |
41 | ptytty::send_fd (int socket, int fd) |
40 | { |
42 | { |
41 | msghdr msg; |
43 | msghdr msg; |
42 | iovec iov; |
44 | iovec iov; |
43 | char buf [CMSG_LEN (sizeof (int))]; |
45 | char buf [CMSG_LEN (sizeof (int))]; |
… | |
… | |
60 | |
62 | |
61 | *(int *)CMSG_DATA (cmsg) = fd; |
63 | *(int *)CMSG_DATA (cmsg) = fd; |
62 | |
64 | |
63 | msg.msg_controllen = cmsg->cmsg_len; |
65 | msg.msg_controllen = cmsg->cmsg_len; |
64 | |
66 | |
65 | return sendmsg (socket, &msg, 0); |
67 | return sendmsg (socket, &msg, 0) >= 0; |
66 | } |
68 | } |
67 | |
69 | |
68 | int |
70 | int |
69 | ptytty::recv_fd (int socket) |
71 | ptytty::recv_fd (int socket) |
70 | { |
72 | { |