|
|
1 | // This file is part of libptytty. Do not make local modifications. |
|
|
2 | // http://software.schmorp.de/pkg/libptytty |
|
|
3 | |
1 | /*--------------------------------*-C-*---------------------------------* |
4 | /*----------------------------------------------------------------------* |
2 | * File: fdpass.C |
5 | * File: fdpass.C |
3 | *----------------------------------------------------------------------* |
6 | *----------------------------------------------------------------------* |
4 | * |
7 | * |
5 | * All portions of code are copyright by their respective author/s. |
8 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
9 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
… | |
… | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
22 | |
25 | |
23 | #include "../config.h" |
26 | #include "../config.h" |
24 | |
27 | |
|
|
28 | #include <cstddef> // needed by freebsd for NULL used in sys/uio.h |
|
|
29 | |
25 | #include <sys/uio.h> |
30 | #include <sys/uio.h> |
26 | #include <sys/types.h> |
31 | #include <sys/types.h> |
27 | #include <sys/socket.h> |
32 | #include <sys/socket.h> |
28 | |
33 | |
29 | #include "fdpass.h" |
34 | #include "libptytty.h" |
30 | |
35 | |
31 | #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 |
32 | # define CMSG_LEN(len) (sizeof (cmsghdr) + len) |
37 | # define CMSG_LEN(len) (sizeof (cmsghdr) + len) |
33 | #endif |
38 | #endif |
34 | |
39 | |
35 | int |
40 | bool |
36 | ptytty_send_fd (int socket, int fd) |
41 | ptytty::send_fd (int socket, int fd) |
37 | { |
42 | { |
38 | msghdr msg; |
43 | msghdr msg; |
39 | iovec iov; |
44 | iovec iov; |
40 | char buf [CMSG_LEN (sizeof (int))]; |
45 | char buf [CMSG_LEN (sizeof (int))]; |
41 | char data = 0; |
46 | char data = 0; |
… | |
… | |
57 | |
62 | |
58 | *(int *)CMSG_DATA (cmsg) = fd; |
63 | *(int *)CMSG_DATA (cmsg) = fd; |
59 | |
64 | |
60 | msg.msg_controllen = cmsg->cmsg_len; |
65 | msg.msg_controllen = cmsg->cmsg_len; |
61 | |
66 | |
62 | return sendmsg (socket, &msg, 0); |
67 | return sendmsg (socket, &msg, 0) >= 0; |
63 | } |
68 | } |
64 | |
69 | |
65 | int |
70 | int |
66 | ptytty_recv_fd (int socket) |
71 | ptytty::recv_fd (int socket) |
67 | { |
72 | { |
68 | msghdr msg; |
73 | msghdr msg; |
69 | iovec iov; |
74 | iovec iov; |
70 | char buf [CMSG_LEN (sizeof (int))]; /* ancillary data buffer */ |
75 | char buf [CMSG_LEN (sizeof (int))]; /* ancillary data buffer */ |
71 | char data = 1; |
76 | char data = 1; |