Clean up IPv4 vs IPv6 bogosity in connectFailureMessage().
Newly added code was supposing that "struct sockaddr_in" applies to IPv6.
This commit is contained in:
parent
3840bc0847
commit
be3b666eb8
|
@ -989,8 +989,7 @@ connectFailureMessage(PGconn *conn, int errorno)
|
||||||
{
|
{
|
||||||
char host_addr[NI_MAXHOST];
|
char host_addr[NI_MAXHOST];
|
||||||
bool display_host_addr;
|
bool display_host_addr;
|
||||||
struct sockaddr_in *host_addr_struct = (struct sockaddr_in *)
|
struct sockaddr_storage *addr = &conn->raddr.addr;
|
||||||
&conn->raddr.addr;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Optionally display the network address with the hostname.
|
* Optionally display the network address with the hostname.
|
||||||
|
@ -998,18 +997,33 @@ connectFailureMessage(PGconn *conn, int errorno)
|
||||||
*/
|
*/
|
||||||
if (conn->pghostaddr != NULL)
|
if (conn->pghostaddr != NULL)
|
||||||
strlcpy(host_addr, conn->pghostaddr, NI_MAXHOST);
|
strlcpy(host_addr, conn->pghostaddr, NI_MAXHOST);
|
||||||
else if (inet_net_ntop(host_addr_struct->sin_family,
|
else if (addr->ss_family == AF_INET)
|
||||||
&host_addr_struct->sin_addr.s_addr,
|
{
|
||||||
host_addr_struct->sin_family == AF_INET ? 32 : 128,
|
if (inet_net_ntop(AF_INET,
|
||||||
|
&((struct sockaddr_in *) addr)->sin_addr.s_addr,
|
||||||
|
32,
|
||||||
host_addr, sizeof(host_addr)) == NULL)
|
host_addr, sizeof(host_addr)) == NULL)
|
||||||
strcpy(host_addr, "???");
|
strcpy(host_addr, "???");
|
||||||
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else if (addr->ss_family == AF_INET6)
|
||||||
|
{
|
||||||
|
if (inet_net_ntop(AF_INET6,
|
||||||
|
&((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
|
||||||
|
128,
|
||||||
|
host_addr, sizeof(host_addr)) == NULL)
|
||||||
|
strcpy(host_addr, "???");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
strcpy(host_addr, "???");
|
||||||
|
|
||||||
display_host_addr = !conn->pghostaddr &&
|
display_host_addr = (conn->pghostaddr == NULL) &&
|
||||||
strcmp(conn->pghost, host_addr) != 0;
|
(strcmp(conn->pghost, host_addr) != 0);
|
||||||
|
|
||||||
appendPQExpBuffer(&conn->errorMessage,
|
appendPQExpBuffer(&conn->errorMessage,
|
||||||
libpq_gettext("could not connect to server: %s\n"
|
libpq_gettext("could not connect to server: %s\n"
|
||||||
"\tIs the server running on host \"%s\" %s%s%sand accepting\n"
|
"\tIs the server running on host \"%s\"%s%s%s and accepting\n"
|
||||||
"\tTCP/IP connections on port %s?\n"),
|
"\tTCP/IP connections on port %s?\n"),
|
||||||
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
|
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
|
||||||
conn->pghostaddr
|
conn->pghostaddr
|
||||||
|
@ -1018,9 +1032,9 @@ connectFailureMessage(PGconn *conn, int errorno)
|
||||||
? conn->pghost
|
? conn->pghost
|
||||||
: "???"),
|
: "???"),
|
||||||
/* display the IP address only if not already output */
|
/* display the IP address only if not already output */
|
||||||
display_host_addr ? "(" : "",
|
display_host_addr ? " (" : "",
|
||||||
display_host_addr ? host_addr : "",
|
display_host_addr ? host_addr : "",
|
||||||
display_host_addr ? ") " : "",
|
display_host_addr ? ")" : "",
|
||||||
conn->pgport);
|
conn->pgport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue