title: Accessing IPv6 resolvable URL with port (e.g. localhost:12345) results in Bad Address in Strawberry Perl 5.30.1
body: <p>When using strawberry perl 5.30.1 under Windows 10 with IPv6 enabled, URLs with Portnumbers cannot be resolved properly due to what appears to be a bug in the DNS parser of Perl.</p>
  
  <p>For the following test, we have a simple webserver listening on Port 8810 for all interfaces.</p>
  
  <p>Port 12345 does <strong>NOT</strong> host anything.</p>
  
  <p>Following is the script we use for reproduction:</p>
  
  <pre class="lang-perl prettyprint-override"><code>use strict;
  use warnings;
  use LWP::UserAgent;
  
  my $ua = LWP::UserAgent-&gt;new();
  my $result=$ua-&gt;get("http://localhost:8810/");
  print "(DNS Expect: Success) The server responded with Status Code ".$result-&gt;status_line.".\n";
  $result=$ua-&gt;get("http://localhost:12345/");
  print "(DNS Expect: Failure) The server responded with Status Code ".$result-&gt;status_line.".\n";
  $result=$ua-&gt;get("http://127.0.0.1:8810/");
  print "(IPv4 Expect: Success) The server responded with Status Code ".$result-&gt;status_line.".\n";
  </code></pre>
  
  <p>When being executed with 5.28.0, I get the correct response</p>
  
  <pre><code>C:\perl-test&gt;strawberry-perl-5-28-0-original\perl\bin\perl.exe test2.pl
  (DNS Expect: Success) The server responded with Status Code 200 OK.
  (DNS Expect: Failure) The server responded with Status Code 500 Can't connect to localhost:12345 (No connection could be made because the target machine actively refused it.).
  (IPv4 Expect: Success) The server responded with Status Code 200 OK.
  </code></pre>
  
  <p>However, when trying with 5.30.1, I get Bad Address, regardless of whether there actually is a port open or not</p>
  
  <pre><code>C:\perl-test&gt;strawberry-perl-5-30-1-original\perl\bin\perl.exe test2.pl
  (DNS Expect: Success) The server responded with Status Code 500 Can't connect to localhost:8810 (Bad address).
  (DNS Expect: Failure) The server responded with Status Code 500 Can't connect to localhost:12345 (Bad address).
  (IPv4 Expect: Success) The server responded with Status Code 200 OK.
  </code></pre>
  
  <p>Note how 5.30.1 still is able to actually request the information if we provide the IPv4 address directly. Also, for DNS that do not resolve to IPv6 but only IPv4, 5.30.1 does not seem to have an issue.</p>
  
  <p>Does anyone else have this issue and if so is this considered a bug or do we just use perl in some wrong way?</p>
  
  <p><strong>UPDATE:</strong> I found another piece of the puzzle that seems to contribute: </p>
  
  <p>We tried so far only on our corporate windows machines, all machines had the same behavior with Perl 5.30.1 and 5.30.2. However, I now also tried my private Windows 10 and it worked. </p>
  
  <p>Then I dug a bit about IPv4 and IPv6 and came up with this knowledge base article from microsoft: <a href="https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users" rel="nofollow noreferrer">https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users</a></p>
  
  <p>Bottom line: I set in the registry that Windows should prefer IPv4 over IPv6 (Setting 0x20), rebooted - and it worked on my corporate windows 10! </p>
  
  <p>So apparently we have some setting that screws with perl but there still seems to be a catch: When trying to access a localhost port that is not reachable, we still get the "Bad address" error instead of "Connection refused", meaning there is still something that is misparsing our dns:port string. </p>
  
  <p>Also, I'd expect perl to fully support IPv6 by now.</p>