7 /* connect to UNIX-domain listener
9 /* #include <connect.h>
11 /* int unix_connect(addr, block_mode, timeout)
16 /* unix_connect() connects to a listener in the UNIX domain at the
17 /* specified address, and returns the resulting file descriptor.
21 /* Null-terminated string with connection destination.
23 /* Either NON_BLOCKING for a non-blocking socket, or BLOCKING for
26 /* Bounds the number of seconds that the operation may take. Specify
27 /* a value <= 0 to disable the time limit.
29 /* The result is -1 in case the connection could not be made.
30 /* Fatal errors: other system call failures.
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
42 /* System interfaces. */
45 #include <sys/socket.h>
51 /* Utility library. */
55 #include "sane_connect.h"
57 #include "timed_connect.h"
59 /* unix_connect - connect to UNIX-domain listener */
61 int unix_connect(const char *addr
, int block_mode
, int timeout
)
64 struct sockaddr_un sun
;
65 int len
= strlen(addr
);
69 * Translate address information to internal form.
71 if (len
>= (int) sizeof(sun
.sun_path
))
72 msg_fatal("unix-domain name too long: %s", addr
);
73 memset((char *) &sun
, 0, sizeof(sun
));
74 sun
.sun_family
= AF_UNIX
;
76 sun
.sun_len
= len
+ 1;
78 memcpy(sun
.sun_path
, addr
, len
+ 1);
81 * Create a client socket.
83 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) < 0)
90 non_blocking(sock
, NON_BLOCKING
);
91 if (timed_connect(sock
, (struct sockaddr
*) & sun
, sizeof(sun
), timeout
) < 0) {
95 if (block_mode
!= NON_BLOCKING
)
96 non_blocking(sock
, block_mode
);
101 * Maybe block until connected.
104 non_blocking(sock
, block_mode
);
105 if (sane_connect(sock
, (struct sockaddr
*) & sun
, sizeof(sun
)) < 0
106 && errno
!= EINPROGRESS
) {