Created
August 1, 2017 10:58
-
-
Save icydee/68a008e5b44544ce8b97e638bdd92526 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use IO::Socket::IP; | |
use Socket qw(SOCK_STREAM AF_INET6); | |
my $testserver = IO::Socket->new; | |
$testserver->socket( AF_INET6, SOCK_STREAM, 0 ) or die "Cannot socket() - $!"; | |
print("TESTSERVER: ".Dumper($testserver)); | |
my ( $err, $ai ) = Socket::getaddrinfo( "::1", 0, { family => AF_INET6, socktype => SOCK_STREAM } ); | |
die "getaddrinfo() - $err" if $err; | |
print("AI: ".Dumper($ai)); | |
$testserver->bind( $ai->{addr} ) or die "Cannot bind() - $!"; | |
$testserver->listen( 1 ) or die "Cannot listen() - $!"; | |
my $testport = ( Socket::unpack_sockaddr_in6 $testserver->sockname )[0]; | |
print("Testport: $testport\n"); | |
my $socket = IO::Socket::IP->new( | |
PeerHost => "::1", | |
PeerService => $testport, | |
Type => SOCK_STREAM, | |
GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG | |
); | |
print("SOCKET: ".Dumper($socket)); | |
##### outputs the following | |
# TESTSERVER: $VAR1 = bless( \*Symbol::GEN0, 'IO::Socket' ); | |
# AI: $VAR1 = { | |
# 'protocol' => 6, | |
# 'addr' => ' | |
# ', | |
# 'socktype' => 1, | |
# 'canonname' => undef, | |
# 'family' => 10 | |
# }; | |
# Testport: 52163 | |
# SOCKET: $VAR1 = undef; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment