sushant.ravale has asked for the wisdom of the Perl Monks concerning the following question:
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 <wildcard>, 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get wildcard addresses using getaddrinfo?
by VinsWorldcom (Prior) on Aug 21, 2012 at 11:48 UTC | |
by sushant.ravale (Initiate) on Aug 21, 2012 at 12:32 UTC |