Cross post on : http://www.perlmonks.org/?node_id=988678
I am new to perl. I am trying to fetch all the wildcard interfaces using getaddrinfo (I am using Socket6 (IO:Socket:IP somehow didn't work on my Windows box)), like:
use Socket;
use Socket6;
@res = getaddrinfo('<wildcard>', 3786, AF_UNSPEC, SOCK_STREAM);
while(scalar(@res)>=5){
($family, $socktype, $proto, $saddr, $canonname, @res) = @res;
($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV);
print ("\nhost= $host port = $port");
}
I am wondering what value should I use for the placeholder , so that I'll get IPv4 as well IPv6 wildcard addresses (0.0.0.0 and ::) in the result, so that I can bind to it independent of the machine I am using (IPv4 or IPv6). In 'c' specifying a null hostname pointer does the job, for perl I tried '', undef but they return loopback addresses.