@@ -989,27 +989,41 @@ connectFailureMessage(PGconn *conn, int errorno)
989989{
990990char host_addr [NI_MAXHOST ];
991991bool display_host_addr ;
992- struct sockaddr_in * host_addr_struct = (struct sockaddr_in * )
993- & conn -> raddr .addr ;
992+ struct sockaddr_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 */
999998if (conn -> pghostaddr != NULL )
1000999strlcpy (host_addr ,conn -> pghostaddr ,NI_MAXHOST );
1001- else if (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+ else if (addr -> ss_family == AF_INET )
1001+ {
1002+ if (inet_net_ntop (AF_INET ,
1003+ & ((struct sockaddr_in * )addr )-> sin_addr .s_addr ,
1004+ 32 ,
1005+ host_addr ,sizeof (host_addr ))== NULL )
1006+ strcpy (host_addr ,"???" );
1007+ }
1008+ #ifdef HAVE_IPV6
1009+ else if (addr -> ss_family == AF_INET6 )
1010+ {
1011+ if (inet_net_ntop (AF_INET6 ,
1012+ & ((struct sockaddr_in6 * )addr )-> sin6_addr .s6_addr ,
1013+ 128 ,
1014+ host_addr ,sizeof (host_addr ))== NULL )
1015+ strcpy (host_addr ,"???" );
1016+ }
1017+ #endif
1018+ else
10051019strcpy (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+
10101024appendPQExpBuffer (& conn -> errorMessage ,
10111025libpq_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" ),
10141028SOCK_STRERROR (errorno ,sebuf ,sizeof (sebuf )),
10151029conn -> 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 ?" (" :"" ,
10221036display_host_addr ?host_addr :"" ,
1023- display_host_addr ?") " :"" ,
1037+ display_host_addr ?")" :"" ,
10241038conn -> pgport );
10251039}
10261040}