diff options
| author | Matthias Andree <matthias.andree@gmx.de> | 2006-05-14 22:13:04 +0000 | 
|---|---|---|
| committer | Matthias Andree <matthias.andree@gmx.de> | 2006-05-14 22:13:04 +0000 | 
| commit | bfc5dfad82e30b45840c26b655b72fd70c06ecee (patch) | |
| tree | 89560114987ecb39bc971a07ca27b4e47c1794d0 /socket.c | |
| parent | ba56cd522a6d4d5ba0c56fc5c532fc3d645313b6 (diff) | |
| download | fetchmail-bfc5dfad82e30b45840c26b655b72fd70c06ecee.tar.gz fetchmail-bfc5dfad82e30b45840c26b655b72fd70c06ecee.tar.bz2 fetchmail-bfc5dfad82e30b45840c26b655b72fd70c06ecee.zip | |
In verbose mode, log every IP fetchmail tries to connect to, to avoid
misleading the user. Suppress EAFNOSUPPORT errors from socket() call,
too.  Fixes Debian Bug #361825.
svn path=/branches/BRANCH_6-3/; revision=4836
Diffstat (limited to 'socket.c')
| -rw-r--r-- | socket.c | 40 | 
1 files changed, 36 insertions, 4 deletions
| @@ -267,7 +267,7 @@ int SockOpen(const char *host, const char *service,  	     const char *plugin)  {      struct addrinfo *ai, *ai0, req; -    int i; +    int i, acterr = 0;  #ifdef HAVE_SOCKETPAIR      if (plugin) @@ -287,28 +287,60 @@ int SockOpen(const char *host, const char *service,      i = -1;      for (ai = ai0; ai; ai = ai->ai_next) { +	char buf[80]; +	int gnie; + +	gnie = getnameinfo(ai->ai_addr, ai->ai_addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); +	if (gnie) +	    snprintf(buf, sizeof(buf), GT_("unknown (%s)"), gai_strerror(gnie)); + +	if (outlevel >= O_VERBOSE) +	    report_build(stdout, GT_("Trying to connect to %s..."), buf);  	i = socket(ai->ai_family, ai->ai_socktype, 0); -	if (i < 0) +	if (i < 0) { +	    /* mask EAFNOSUPPORT errors, they confuse users for +	     * multihomed hosts */ +	    if (errno != EAFNOSUPPORT) +		acterr = errno; +	    if (outlevel >= O_VERBOSE) +		report_complete(stdout, GT_("cannot create socket: %s\n"), strerror(errno));  	    continue; +	}  	/* Save socket descriptor.  	 * Used to close the socket after connect timeout. */  	mailserver_socket_temp = i;  	if (connect(i, (struct sockaddr *) ai->ai_addr, ai->ai_addrlen) < 0) { +	    int e = errno; + +	    /* additionally, suppress IPv4 network unreach errors */ +	    if (e != EAFNOSUPPORT) +		acterr = errno; + +	    if (outlevel >= O_VERBOSE) +		report_complete(stdout, GT_("connection failed.\n")); +	    if (outlevel > O_SILENT) +		report(stderr, GT_("connection to %s failed: %s.\n"), buf, strerror(e));  	    fm_close(i);  	    i = -1;  	    continue; +	} else { +	    if (outlevel >= O_VERBOSE) +		report_complete(stdout, GT_("connected.\n"));  	} -	 +  	/* No connect timeout, then no need to set mailserver_socket_temp */  	mailserver_socket_temp = -1; -	 +  	break;      }      freeaddrinfo(ai0); +    if (i == -1) +	errno = acterr; +      return i;  } | 
