#endif /* HAVE_UNIX_SOCKETS */
{
char host_addr[NI_MAXHOST];
- bool display_host_addr;
+ const char *displayed_host;
struct sockaddr_storage *addr = &conn->raddr.addr;
/*
else
strcpy(host_addr, "???");
+ if (conn->pghostaddr && conn->pghostaddr[0] != '\0')
+ displayed_host = conn->pghostaddr;
+ else if (conn->pghost && conn->pghost[0] != '\0')
+ displayed_host = conn->pghost;
+ else
+ displayed_host = DefaultHost;
+
/*
* If the user did not supply an IP address using 'hostaddr', and
* 'host' was missing or does not match our lookup, display the
* looked-up IP address.
*/
- display_host_addr = (conn->pghostaddr == NULL) &&
- ((conn->pghost == NULL) ||
- (strcmp(conn->pghost, host_addr) != 0));
-
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("could not connect to server: %s\n"
- "\tIs the server running on host \"%s\"%s%s%s and accepting\n"
- "\tTCP/IP connections on port %s?\n"),
- SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
- (conn->pghostaddr && conn->pghostaddr[0] != '\0')
- ? conn->pghostaddr
- : (conn->pghost && conn->pghost[0] != '\0')
- ? conn->pghost
- : DefaultHost,
- /* display the IP address only if not already output */
- display_host_addr ? " (" : "",
- display_host_addr ? host_addr : "",
- display_host_addr ? ")" : "",
- conn->pgport);
+ if ((conn->pghostaddr == NULL) &&
+ (conn->pghost == NULL || strcmp(conn->pghost, host_addr) != 0))
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("could not connect to server: %s\n"
+ "\tIs the server running on host \"%s\" (%s) and accepting\n"
+ "\tTCP/IP connections on port %s?\n"),
+ SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
+ displayed_host,
+ host_addr,
+ conn->pgport);
+ else
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("could not connect to server: %s\n"
+ "\tIs the server running on host \"%s\" and accepting\n"
+ "\tTCP/IP connections on port %s?\n"),
+ SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
+ displayed_host,
+ conn->pgport);
}
}