- /* Find the internet address of the NNTP server */
-- *hi = get_hostent(realhost);
-- if(*hi == NULL) {
-+ hi = get_addrinfo(v4only ? PF_INET : PF_UNSPEC, realhost, sport);
-+ if (hi == NULL)
-+ {
- error_log(ERRLOG_REPORT,"%v1%: ",realhost, NULL);
- MyPerror(both_phrases[2]);
-- free(realhost);
-+ free(bufhost);
- }
-- else {
-- free(realhost);
-- print_phrases(msgs, both_phrases[3], (*hi)->h_name, NULL);
-- while((ptr = *((*hi)->h_aliases)) != NULL) {
-- print_phrases(msgs, both_phrases[4], ptr, NULL );
-- (*hi)->h_aliases++;
-- }
-- if((*hi)->h_addrtype != AF_INET) {
-- error_log(ERRLOG_REPORT, both_phrases[5], NULL);
-+ else
-+ {
-+ int supported_pf = 0;
-+ char *canonname = hi->ai_canonname ? hi->ai_canonname : realhost;
-+
-+ struct addrinfo *hi_ptr = hi;
-+
-+ char *vhost = NULL;
-+ struct addrinfo *hi_vhost = NULL;
-+
-+ print_phrases(msgs, both_phrases[3], canonname, NULL);
-+
-+ if (!v4only)
-+ {
-+ // init IPv6 virtual host functionality.
-+
-+ // if the VHOST environment variable is set, try to use its value
-+ // as the local address for the outgoing connection.
-+
-+ vhost = getenv("VHOST");
-+
-+ if (vhost)
-+ {
-+ hi_vhost = get_addrinfo(PF_INET6, vhost, NULL);
-+
-+ if (!hi_vhost)
-+ {
-+ print_phrases(msgs, "Invalid VHOST: %v1%\n", vhost, NULL);
-+ }
-+ }
- }
-- else {
-- while((aptr = (struct in_addr *)*((*hi)->h_addr_list)++) != NULL) {
-- saddr = *aptr;
-- print_phrases(msgs, both_phrases[17], inet_ntoa(*aptr), NULL);
-- }
--
-- /* Create a socket */
-- if((sockfd = socket( AF_INET, SOCK_STREAM, SOCKET_PROTOCOL)) == -1) {
-- MyPerror(both_phrases[6]);
-- }
-- else {
-- address.sin_family = AF_INET;
-- address.sin_port = htons(portnr); /* NNTP port */
-- address.sin_addr= saddr;
--
-- /* Establish a connection */
-- if(connect(sockfd, (struct sockaddr *)&address, sizeof address ) == -1) {
-- MyPerror(both_phrases[7]);
-- close(sockfd);
-- sockfd = -1;
-+
-+ while (hi_ptr)
-+ {
-+ if ((hi_ptr->ai_family == PF_INET) || (hi_ptr->ai_family == PF_INET6))
-+ {
-+ char num_host[NI_MAXHOST];
-+
-+ supported_pf++;
-+
-+ if (!getnameinfo(hi_ptr->ai_addr, hi_ptr->ai_addrlen, num_host, sizeof(num_host), NULL, 0, NI_NUMERICHOST))
-+ print_phrases(msgs, both_phrases[17], num_host, NULL);
-+
-+ /* Create a socket */
-+ if ((sockfd = socket(hi_ptr->ai_family, SOCK_STREAM, SOCKET_PROTOCOL)) < 0)
-+ {
-+ MyPerror(both_phrases[6]);
- }
-- else {
-- print_phrases(msgs,both_phrases[8], (*hi)->h_name, NULL);
-+ else
-+ {
-+ if ((hi_ptr->ai_family == PF_INET6) && (hi_vhost))
-+ {
-+ // IPv6 virtual host in action:
-+ // explicitly bind() the socket to the specified local address
-+
-+ if (bind(sockfd, hi_vhost->ai_addr, hi_vhost->ai_addrlen) < 0)
-+ {
-+ print_phrases(msgs, "Invalid VHOST: %v1%\n", vhost, NULL);
-+ }
-+ else
-+ {
-+ print_phrases(msgs, "VHOST: %v1%\n", vhost, NULL);
-+ }
-+ }
-+
-+ /* Establish a connection */
-+ if (connect(sockfd, hi_ptr->ai_addr, hi_ptr->ai_addrlen) < 0)
-+ {
-+ MyPerror(both_phrases[7]);
-+ close(sockfd);
-+ sockfd = -1;
-+ }
-+ else
-+ {
-+ print_phrases(msgs, both_phrases[8], canonname, NULL);
-+ break;
-+ }
- }
-- }
-+ }
-+
-+ hi_ptr = hi_ptr->ai_next;
-+ }
-+
-+ if (!supported_pf)
-+ {
-+ error_log(ERRLOG_REPORT, both_phrases[5], NULL);
- }
-+
-+ free(bufhost);
-+ free_addrinfo(hi);
-+ free_addrinfo(hi_vhost);
-+
- #ifdef HAVE_LIBSSL
- if(sockfd > -1 && do_ssl == TRUE) {
- if((ssl_struct = SSL_new(test1)) == NULL) {
-diff -ur suck-4.3.2-orig/both.h suck-4.3.2/both.h
---- suck-4.3.2-orig/both.h 2002-08-28 00:54:34.000000000 +0200
-+++ suck-4.3.2/both.h 2007-03-22 18:56:20.000000000 +0100
-@@ -9,11 +9,12 @@