Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe3b666

Browse files
committed
Clean up IPv4 vs IPv6 bogosity in connectFailureMessage().
Newly added code was supposing that "struct sockaddr_in" applies to IPv6.
1 parent3840bc0 commitbe3b666

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -989,27 +989,41 @@ connectFailureMessage(PGconn *conn, int errorno)
989989
{
990990
charhost_addr[NI_MAXHOST];
991991
booldisplay_host_addr;
992-
structsockaddr_in*host_addr_struct= (structsockaddr_in*)
993-
&conn->raddr.addr;
992+
structsockaddr_storage*addr=&conn->raddr.addr;
994993

995994
/*
996995
*Optionally display the network address with the hostname.
997996
*This is useful to distinguish between IPv4 and IPv6 connections.
998997
*/
999998
if (conn->pghostaddr!=NULL)
1000999
strlcpy(host_addr,conn->pghostaddr,NI_MAXHOST);
1001-
elseif (inet_net_ntop(host_addr_struct->sin_family,
1002-
&host_addr_struct->sin_addr.s_addr,
1003-
host_addr_struct->sin_family==AF_INET ?32 :128,
1004-
host_addr,sizeof(host_addr))==NULL)
1000+
elseif (addr->ss_family==AF_INET)
1001+
{
1002+
if (inet_net_ntop(AF_INET,
1003+
&((structsockaddr_in*)addr)->sin_addr.s_addr,
1004+
32,
1005+
host_addr,sizeof(host_addr))==NULL)
1006+
strcpy(host_addr,"???");
1007+
}
1008+
#ifdefHAVE_IPV6
1009+
elseif (addr->ss_family==AF_INET6)
1010+
{
1011+
if (inet_net_ntop(AF_INET6,
1012+
&((structsockaddr_in6*)addr)->sin6_addr.s6_addr,
1013+
128,
1014+
host_addr,sizeof(host_addr))==NULL)
1015+
strcpy(host_addr,"???");
1016+
}
1017+
#endif
1018+
else
10051019
strcpy(host_addr, "???");
10061020

1007-
display_host_addr=!conn->pghostaddr&&
1008-
strcmp(conn->pghost,host_addr)!=0;
1009-
1021+
display_host_addr=(conn->pghostaddr==NULL)&&
1022+
(strcmp(conn->pghost,host_addr)!=0);
1023+
10101024
appendPQExpBuffer(&conn->errorMessage,
10111025
libpq_gettext("could not connect to server: %s\n"
1012-
"\tIs the server running on host \"%s\"%s%s%sand accepting\n"
1026+
"\tIs the server running on host \"%s\"%s%s%s and accepting\n"
10131027
"\tTCP/IP connections on port %s?\n"),
10141028
SOCK_STRERROR(errorno,sebuf,sizeof(sebuf)),
10151029
conn->pghostaddr
@@ -1018,9 +1032,9 @@ connectFailureMessage(PGconn *conn, int errorno)
10181032
?conn->pghost
10191033
:"???"),
10201034
/* display the IP address only if not already output */
1021-
display_host_addr ?"(" :"",
1035+
display_host_addr ?"(" :"",
10221036
display_host_addr ?host_addr :"",
1023-
display_host_addr ?")" :"",
1037+
display_host_addr ?")" :"",
10241038
conn->pgport);
10251039
}
10261040
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp