@@ -1030,20 +1030,25 @@ connectFailureMessage(PGconn *conn, int errorno)
10301030 else
10311031 strcpy (host_addr , "???");
10321032
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+ */
10331038 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 ) );
10361041
10371042 appendPQExpBuffer (& conn -> errorMessage ,
10381043 libpq_gettext ("could not connect to server: %s\n"
10391044 "\tIs the server running on host \"%s\"%s%s%s and accepting\n"
10401045 "\tTCP/IP connections on port %s?\n" ),
10411046 SOCK_STRERROR (errorno , sebuf , sizeof (sebuf )),
1042- conn -> pghostaddr
1047+ ( conn -> pghostaddr && conn -> pghostaddr [ 0 ] != '\0' )
10431048 ? conn -> pghostaddr
1044- : (conn -> pghost
1049+ : (conn -> pghost && conn -> pghost [ 0 ] != '\0' )
10451050 ? conn -> pghost
1046- : "???" ) ,
1051+ : DefaultHost ,
10471052 /* display the IP address only if not already output */
10481053 display_host_addr ? " (" : "" ,
10491054 display_host_addr ? host_addr : "" ,
@@ -1304,7 +1309,7 @@ connectDBStart(PGconn *conn)
13041309 UNIXSOCK_PATH (portstr , portnum , conn -> pgunixsocket );
13051310#else
13061311 /* Without Unix sockets, default to localhost instead */
1307- node = "localhost" ;
1312+ node = DefaultHost ;
13081313 hint .ai_family = AF_UNSPEC ;
13091314#endif /* HAVE_UNIX_SOCKETS */
13101315 }
@@ -3388,7 +3393,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
33883393 /* hostname */
33893394 hostname = url + strlen (LDAP_URL );
33903395 if (* hostname == '/' ) /* no hostname? */
3391- hostname = "localhost" ; /* the default */
3396+ hostname = DefaultHost ; /* the default */
33923397
33933398 /* dn, "distinguished name" */
33943399 p = strchr (url + strlen (LDAP_URL ), '/' );
0 commit comments