From 343eedd542a30c183f2d134b7668d07cab0a5769 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 1 Nov 1996 18:05:40 +0000 Subject: Deal with connect(2) bug. svn path=/trunk/; revision=465 --- socket.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'socket.c') diff --git a/socket.c b/socket.c index f0020adf..9d716dcb 100644 --- a/socket.c +++ b/socket.c @@ -51,8 +51,19 @@ int clientPort; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) return (FILE *)NULL; - if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) + + /* + * Return of connect(2) doesn't seem to reliably return -1 on + * ENETUNREACH failure + */ + errno = 0; + connect(sock, (struct sockaddr *) &ad, sizeof(ad)); + if (errno != 0); + { + close(sock); return (FILE *)NULL; + } + return fdopen(sock, "r+"); } -- cgit v1.2.3