title: What is best way to know if OS/platform supports IPv6 socket to listen IPv4 as well in Perl?
body: <p>(Please close this thread if duplicate, I tried hard, but couldn't find any matching question)</p>
  
  <p>It seems some OS/platforms listen for both IPv6 and IPv4 (tcp) connections when bound to IPv6 widcard address, while some listen for only IPv6, as mentioned in:</p>
  
  <p><a href="http://search.cpan.org/~pevans/IO-Socket-IP-0.17/lib/IO/Socket/IP.pm" rel="nofollow noreferrer">for the V6Only argument</a></p>
  
  <p>with the following lines: </p>
  
  <blockquote>
    <p>If your platform does not support disabling this option but you still want to listen for both AF_INET and AF_INET6 connections you will have to create two listening sockets, one bound to each protocol</p>
  </blockquote>
  
  <p>And in the section "<a href="http://docs.oracle.com/javase/1.5.0/docs/guide/net/ipv6_guide/index.html" rel="nofollow noreferrer">How IPv6 Works on a Java Platform</a>"</p>
  
  <p>And as per correct answer <a href="https://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections">in this SO question</a></p>
  
  <p>Now I want to write some Perl code which can determine if the underlying OS/platform listens for both IPv6 and IPv4 (if bound to IPv6), if yes, I'll bind to IPv6 only, if no I'll create 2 sockets (1 for IPv4 and another for IPv6).</p>
  
  <p>I wonder what could be the best way for this?</p>
  
  <p>As mentioned in <a href="https://metacpan.org/pod/IO::Socket::IP" rel="nofollow noreferrer">IO::Socket::IP</a> I could use </p>
  
  <pre><code>if( IO::Socket::IP-&gt;CAN_DISABLE_V6ONLY ) {
      ...
  }
  else {
      ...
  }
  </code></pre>
  
  <p>But, I am not sure if it will tell me exactly </p>
  
  <blockquote>
    <p>if the underlying OS/platform listens  for both IPv6 and IPv4 (if bound to IPv6)</p>
  </blockquote>
  
  <p>Or it will just tells that the </p>
  
  <blockquote>
    <p>IPV6_V6ONLY socket option cannot be disabled</p>
  </blockquote>