1
This library provide an easy interface to the black magic that can be done
2
on Unix domain sockets, like passing file descriptors from one process to
5
Programs that uses this library should include the ancillary.h header file.
6
Nothing else is required.
8
All functions of this library require the following header:
10
#include <ancillary.h>
12
At this time, the only ancillary data defined by the Single Unix
13
Specification (v3) is file descriptors.
15
Passing file descriptors
17
int ancil_send_fd(socket, file_descriptor)
18
int socket: the Unix socket
19
int file_descriptor: the file descriptor
20
Return value: 0 for success, -1 for failure.
22
Sends one file descriptor on a socket.
23
In case of failure, errno is set; the possible values are the ones of the
24
sendmsg(2) system call.
27
int ancil_recv_fd(socket, file_descriptor)
28
int socket: the Unix socket
29
int *file_descriptor: pointer to the returned file descriptor
30
Return value: 0 for success, -1 for failure
32
Receives one file descriptor from a socket.
33
In case of success, the file descriptor is stored in the integer pointed
34
to by file_descriptor.
35
In case of failure, errno is set; the possible values are the ones of the
36
recvmsg(2) system call.
37
The behavior is undefined if the recv_fd does not match a send_fd* on the
41
int ancil_send_fds(socket, file_descriptors, num_file_descriptors)
42
int socket: the Unix socket
43
const int *file_descriptors: array of file descriptors
44
unsigned num_file_descriptors: number of file descriptors
45
Return value: 0 for success, -1 for failure
47
Sends several file descriptors on a socket.
48
In case of failure, errno is set; the possible values are the ones of the
49
sendmsg(2) system call.
50
The maximum number of file descriptors that can be sent using this
51
function is ANCIL_MAX_N_FDS; the behavior is undefined in case of
52
overflow, probably a stack corruption.
55
int ancil_recv_fds(socket, file_descriptors, num_file_descriptors)
56
int socket: the Unix socket
57
int *file_descriptors: return array of file descriptors
58
unsigned num_file_descriptors: number of file descriptors
59
Return value: number of received fd for success, -1 for failure
61
Receives several file descriptors from a socket, no more than
63
In case of success, the received file descriptors are stored in the array
64
pointed to by file_descriptors.
65
In case of failure, errno is set; the possible values are the ones of the
66
recvmsg(2) system call.
67
The maximum number of file descriptors that can be received using this
68
function is ANCIL_MAX_N_FDS; the behavior is undefined in case of
69
overflow, probably a stack corruption.
70
The behavior is undefined if the recv_fds does not match a send_fd* on
71
the other side, or if the number of received file descriptors is more than
75
int ancil_send_fds_with_buffer(socket, fds, num, buffer)
76
int socket: the Unix socket
77
const int *fds: array of file descriptors
78
unsigned num: number of file descriptors
79
void *buffer: buffer to hold the system data structures
80
Return value: 0 for success, -1 for failure
82
Sends several file descriptors on a socket.
83
In case of failure, errno is set; the possible values are the ones of the
84
sendmsg(2) system call.
85
The buffer argument must point to a memory area large enough to hold the
86
system data structures, see ANCIL_FD_BUFFER.
89
int ancil_send_fds_with_buffer(socket, fds, num, buffer)
90
int socket: the Unix socket
91
int *fds: return array of file descriptors
92
unsigned num: number of file descriptors
93
void *buffer: buffer to hold the system data structures
94
Return value: number of received fd for success, -1 for failure
96
Receives several file descriptors from a socket, no more than
98
In case of success, the received file descriptors are stored in the array
99
pointed to by file_descriptors.
100
In case of failure, errno is set; the possible values are the ones of the
101
recvmsg(2) system call.
102
The behavior is undefined if the recv_fds does not match a send_fd* on
103
the other side, or if the number of received file descriptors is more than
104
num_file_descriptors.
105
The buffer argument must point to a memory area large enough to hold the
106
system data structures, see ANCIL_FD_BUFFER.
111
Maximum number of file descriptors that can be sent with the sent_fds and
112
recv_fds functions. If you have to send more at once, use the
113
*_with_buffer versions. The value is enough to send "quite a few" file
118
int n: number of file descriptors
120
Expands to a structure data type large enough to hold the system data
121
structures for n file descriptors. So the address of a variable declared
122
of type ANCIL_FD_BUFFER(n) is suitable as the buffer argument for
123
*_with_buffer on n file descriptors.
124
To use this macro, you need <sys/types.h> and <sys/socket.h>. Bevare: with
125
Solaris, the _XPG4_2 macro must be defined before sys/socket is included.
128
Tuning the compilation
130
This library is designed to be included in projects, not installed in
131
/usr/lib. If your project does not use some of the functions, the
132
TUNE_OPTS variable in the Makefile allows not to build them. It is a list
133
of proprocessor options:
135
-DNDEBUG: turn assertions off (see assert(3))
136
-DSPARE_SEND_FDS: do not build ancil_send_fds
137
-DSPARE_SEND_FD: do not build ancil_send_fd
138
-DSPARE_RECV_FDS: do not build ancil_recv_fds
139
-DSPARE_RECV_FD: do not build ancil_recv_fd