From 340bfcc4a84a658da8e62071879b19f40d6f6d32 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 20 Mar 2006 20:34:32 +0000 Subject: [PATCH] handle socket() failure and correctly report gethostbyname() failure. --- src/drv_imap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 101348a..1a0757e 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -1265,7 +1265,7 @@ imap_open_store( store_conf_t *conf ) infon( "Resolving %s... ", srvc->host ); he = gethostbyname( srvc->host ); if (!he) { - perror( "gethostbyname" ); + error( "IMAP error: Cannot resolve server '%s'\n", srvc->host ); goto bail; } info( "ok\n" ); @@ -1273,6 +1273,10 @@ imap_open_store( store_conf_t *conf ) addr.sin_addr.s_addr = *((int *) he->h_addr_list[0]); s = socket( PF_INET, SOCK_STREAM, 0 ); + if (s < 0) { + perror( "socket" ); + exit( 1 ); + } infon( "Connecting to %s:%hu... ", inet_ntoa( addr.sin_addr ), ntohs( addr.sin_port ) ); if (connect( s, (struct sockaddr *)&addr, sizeof(addr) )) {