@@ -1030,20 +1030,25 @@ connectFailureMessage(PGconn *conn, int errorno)
1030
1030
else
1031
1031
strcpy (host_addr , "???");
1032
1032
1033
+ /*
1034
+ * If the user did not supply an IP address using 'hostaddr', and
1035
+ * 'host' was missing or does not match our lookup, display the
1036
+ * looked-up IP address.
1037
+ */
1033
1038
display_host_addr = (conn -> pghostaddr == NULL ) &&
1034
- (conn -> pghost != NULL ) &&
1035
- (strcmp (conn -> pghost , host_addr ) != 0 );
1039
+ (( conn -> pghost == NULL ) ||
1040
+ (strcmp (conn -> pghost , host_addr ) != 0 ) );
1036
1041
1037
1042
appendPQExpBuffer (& conn -> errorMessage ,
1038
1043
libpq_gettext ("could not connect to server: %s\n"
1039
1044
"\tIs the server running on host \"%s\"%s%s%s and accepting\n"
1040
1045
"\tTCP/IP connections on port %s?\n" ),
1041
1046
SOCK_STRERROR (errorno , sebuf , sizeof (sebuf )),
1042
- conn -> pghostaddr
1047
+ ( conn -> pghostaddr && conn -> pghostaddr [ 0 ] != '\0' )
1043
1048
? conn -> pghostaddr
1044
- : (conn -> pghost
1049
+ : (conn -> pghost && conn -> pghost [ 0 ] != '\0' )
1045
1050
? conn -> pghost
1046
- : "???" ) ,
1051
+ : DefaultHost ,
1047
1052
/* display the IP address only if not already output */
1048
1053
display_host_addr ? " (" : "" ,
1049
1054
display_host_addr ? host_addr : "" ,
@@ -1304,7 +1309,7 @@ connectDBStart(PGconn *conn)
1304
1309
UNIXSOCK_PATH (portstr , portnum , conn -> pgunixsocket );
1305
1310
#else
1306
1311
/* Without Unix sockets, default to localhost instead */
1307
- node = "localhost" ;
1312
+ node = DefaultHost ;
1308
1313
hint .ai_family = AF_UNSPEC ;
1309
1314
#endif /* HAVE_UNIX_SOCKETS */
1310
1315
}
@@ -3388,7 +3393,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
3388
3393
/* hostname */
3389
3394
hostname = url + strlen (LDAP_URL );
3390
3395
if (* hostname == '/' ) /* no hostname? */
3391
- hostname = "localhost" ; /* the default */
3396
+ hostname = DefaultHost ; /* the default */
3392
3397
3393
3398
/* dn, "distinguished name" */
3394
3399
p = strchr (url + strlen (LDAP_URL ), '/' );
0 commit comments