handle socket() failure and correctly report gethostbyname() failure.
This commit is contained in:
		
							parent
							
								
									3e3cf3ac9a
								
							
						
					
					
						commit
						340bfcc4a8
					
				
					 1 changed files with 5 additions and 1 deletions
				
			
		| 
						 | 
					@ -1265,7 +1265,7 @@ imap_open_store( store_conf_t *conf )
 | 
				
			||||||
		infon( "Resolving %s... ", srvc->host );
 | 
							infon( "Resolving %s... ", srvc->host );
 | 
				
			||||||
		he = gethostbyname( srvc->host );
 | 
							he = gethostbyname( srvc->host );
 | 
				
			||||||
		if (!he) {
 | 
							if (!he) {
 | 
				
			||||||
			perror( "gethostbyname" );
 | 
								error( "IMAP error: Cannot resolve server '%s'\n", srvc->host );
 | 
				
			||||||
			goto bail;
 | 
								goto bail;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		info( "ok\n" );
 | 
							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]);
 | 
							addr.sin_addr.s_addr = *((int *) he->h_addr_list[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		s = socket( PF_INET, SOCK_STREAM, 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 ) );
 | 
							infon( "Connecting to %s:%hu... ", inet_ntoa( addr.sin_addr ), ntohs( addr.sin_port ) );
 | 
				
			||||||
		if (connect( s, (struct sockaddr *)&addr, sizeof(addr) )) {
 | 
							if (connect( s, (struct sockaddr *)&addr, sizeof(addr) )) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue