in reply to please provide solution to convert the follwoing IPv4 Socket functions to Ipv6 using Socket6
If you want to support both IPv4 and IPv6, you'd use the code in Socket6's Synopsis. (Adjusted for your needs below.)
use strict; use warnings; use Socket; use Socket6; my @res = getaddrinfo($D{'XXTarget'}, $D{'XXPort'}, AF_UNSPEC, SOCK_ST +REAM); my $sock; my $host; my $port; while (@res >= 5) { my ($family, $socktype, $proto, $saddr, $canonname) = splice(@res, +0, 5); ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSER +V); # log("Trying to connect to $host port port $port...\n"); socket($sock, $family, $socktype, $proto) or next; connect($sock, $saddr) and last; undef $sock; } if (not defined $sock) { ... Handle error ... } ... $sock is connected. $host and $post are available ...
|
|---|