1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*++
/* NAME
/* stream_listen 3
/* SUMMARY
/* start stream listener
/* SYNOPSIS
/* #include <listen.h>
/*
/* int stream_listen(path, backlog, block_mode)
/* const char *path;
/* int backlog;
/* int block_mode;
/*
/* int stream_accept(fd)
/* int fd;
/* DESCRIPTION
/* This module implements a substitute local IPC for systems that do
/* not have properly-working UNIX-domain sockets.
/*
/* stream_listen() creates a listener endpoint with the specified
/* permissions, and returns a file descriptor to be used for accepting
/* connections.
/*
/* stream_accept() accepts a connection.
/*
/* Arguments:
/* .IP path
/* Null-terminated string with connection destination.
/* .IP backlog
/* This argument exists for compatibility and is ignored.
/* .IP block_mode
/* Either NON_BLOCKING or BLOCKING. This does not affect the
/* mode of accepted connections.
/* .IP fd
/* File descriptor returned by stream_listen().
/* DIAGNOSTICS
/* Fatal errors: stream_listen() aborts upon any system call failure.
/* stream_accept() leaves all error handling up to the caller.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System interfaces. */
#include <sys_defs.h>
#ifdef STREAM_CONNECTIONS
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <stropts.h>
#include <fcntl.h>
#endif
/* Utility library. */
#include "msg.h"
#include "listen.h"
/* stream_listen - create stream listener */
int stream_listen(const char *path, int unused_backlog, int block_mode)
{
#ifdef STREAM_CONNECTIONS
/*
* We can't specify a listen backlog, however, sending file descriptors
* across a FIFO gives us a backlog buffer of 460 on Solaris 2.4/SPARC.
*/
return (fifo_listen(path, 0622, block_mode));
#else
msg_fatal("stream connections are not implemented");
#endif
}
/* stream_accept - accept stream connection */
int stream_accept(int fd)
{
#ifdef STREAM_CONNECTIONS
struct strrecvfd fdinfo;
/*
* This will return EAGAIN on a non-blocking stream when someone else
* snatched the connection from us.
*/
if (ioctl(fd, I_RECVFD, &fdinfo) < 0)
return (-1);
return (fdinfo.fd);
#else
msg_fatal("stream connections are not implemented");
#endif
}
|