7 /* sanitize connect() results
9 /* #include <sane_connect.h>
11 /* int sane_connect(sock, buf, len)
13 /* struct sockaddr *buf;
14 /* SOCKADDR_SIZE *len;
16 /* sane_connect() implements the connect(2) socket call, and maps
17 /* known harmless error results to EAGAIN.
19 /* Bizarre systems may have other harmless error results. Such
20 /* systems encourage programmers to ignore error results, and
21 /* penalize programmers who code defensively.
25 /* The Secure Mailer license must be distributed with this software.
28 /* IBM T.J. Watson Research
30 /* Yorktown Heights, NY 10598, USA
36 #include <sys/socket.h>
39 /* Utility library. */
42 #include "sane_connect.h"
44 /* sane_connect - sanitize connect() results */
46 int sane_connect(int sock
, struct sockaddr
* sa
, SOCKADDR_SIZE len
)
50 * XXX Solaris select() produces false read events, so that read() blocks
51 * forever on a blocking socket, and fails with EAGAIN on a non-blocking
52 * socket. Turning on keepalives will fix a blocking socket provided that
53 * the kernel's keepalive timer expires before the Postfix watchdog
56 * XXX Work around NAT induced damage by sending a keepalive before an idle
57 * connection is expired. This requires that the kernel keepalive timer
58 * is set to a short time, like 100s.
60 if (sa
->sa_family
== AF_INET
) {
63 (void) setsockopt(sock
, SOL_SOCKET
, SO_KEEPALIVE
,
64 (char *) &on
, sizeof(on
));
66 return (connect(sock
, sa
, len
));