Check all IPv6 addresses, and also handle case where no HTTP reply is received

This commit is contained in:
Jamie Cameron
2021-01-20 21:30:28 -08:00
parent f8798ee530
commit 8a6f778410

View File

@@ -2534,6 +2534,7 @@ my $h = &make_http_connection($host, $port, $ssl, "GET", $page, \@headers);
alarm(0) if ($timeout); alarm(0) if ($timeout);
$h = $main::download_timed_out if ($main::download_timed_out); $h = $main::download_timed_out if ($main::download_timed_out);
if (!ref($h)) { if (!ref($h)) {
$h ||= "Unknown error";
if ($error) { $$error = $h; return; } if ($error) { $$error = $h; return; }
else { &error(&html_escape($h)); } else { &error(&html_escape($h)); }
} }
@@ -2562,6 +2563,7 @@ $timeout = 60 if (!defined($timeout));
alarm($timeout) if ($timeout); alarm($timeout) if ($timeout);
($line = &read_http_connection($h)) =~ tr/\r\n//d; ($line = &read_http_connection($h)) =~ tr/\r\n//d;
if ($line !~ /^HTTP\/1\..\s+(200|30[0-9]|400)(\s+|$)/) { if ($line !~ /^HTTP\/1\..\s+(200|30[0-9]|400)(\s+|$)/) {
$line ||= "Failed to read HTTP response line";
alarm(0) if ($timeout); alarm(0) if ($timeout);
&close_http_connection($h); &close_http_connection($h);
if ($error) { ${$error} = $line; return; } if ($error) { ${$error} = $line; return; }
@@ -3126,8 +3128,7 @@ if ($gconfig{'debug_what_net'}) {
# Lookup all IPv4 and v6 addresses for the host # Lookup all IPv4 and v6 addresses for the host
my @ips = &to_ipaddress($host); my @ips = &to_ipaddress($host);
my $v6 = &to_ip6address($host); push(@ips, &to_ip6address($host));
push(@ips, $v6) if ($v6);
if (!@ips) { if (!@ips) {
my $msg = "Failed to lookup IP address for $host"; my $msg = "Failed to lookup IP address for $host";
if ($err) { $$err = $msg; return 0; } if ($err) { $$err = $msg; return 0; }
@@ -3289,25 +3290,30 @@ Converts a hostname to IPv6 address, or returns undef if it cannot be resolved.
=cut =cut
sub to_ip6address sub to_ip6address
{ {
if (&check_ip6address($_[0])) { my ($host) = @_;
return $_[0]; # Already in v6 format my @rv;
if (&check_ip6address($host)) {
@rv = ( $host ); # Already in v6 format
} }
elsif (&check_ipaddress($_[0])) { elsif (&check_ipaddress($host)) {
return undef; # A v4 address cannot be v6 @rv = ( ); # A v4 address cannot be v6
} }
elsif (!&supports_ipv6()) { elsif (!&supports_ipv6()) {
return undef; # Cannot lookup @rv = ( ); # v6 lookups not supported
} }
else { else {
# Perform IPv6 DNS lookup # Perform IPv6 DNS lookup
my $inaddr; my @ai = getaddrinfo($host, undef, AF_INET6(), SOCK_STREAM);
(undef, undef, undef, $inaddr) = while(@ai) {
getaddrinfo($_[0], undef, AF_INET6(), SOCK_STREAM); (undef, undef, undef, $inaddr, undef, @ai) = @ai;
return undef if (!$inaddr); if ($inaddr) {
my $addr; my $addr;
(undef, $addr) = unpack_sockaddr_in6($inaddr); (undef, $addr) = unpack_sockaddr_in6($inaddr);
return inet_ntop(AF_INET6(), $addr); push(@rv, inet_ntop(AF_INET6(), $addr));
}
}
} }
return wantarray ? @rv : $rv[0];
} }
=head2 to_hostname(ipv4|ipv6-address) =head2 to_hostname(ipv4|ipv6-address)
@@ -7700,7 +7706,8 @@ else {
} }
} }
=head2 make_http_connection(host, port, ssl, method, page, [&headers]) =head2 make_http_connection(host, port, ssl, method, page, [&headers],
[&certreqs])
Opens a connection to some HTTP server, maybe through a proxy, and returns Opens a connection to some HTTP server, maybe through a proxy, and returns
a handle object. The handle can then be used to send additional headers a handle object. The handle can then be used to send additional headers