1#!/usr/bin/perl 2 3use v5.14; 4use warnings; 5 6use Test::More; 7 8use IO::Socket::IP; 9use Socket 1.95 qw( 10 PF_INET SOCK_STREAM IPPROTO_TCP pack_sockaddr_in INADDR_ANY 11 AI_PASSIVE 12); 13 14my $AI_ADDRCONFIG = eval { Socket::AI_ADDRCONFIG() } || 0; 15 16my @gai_args; 17my @gai_rets; 18 19no strict 'refs'; 20no warnings 'redefine'; 21 22*{"IO::Socket::IP::getaddrinfo"} = sub { 23 push @gai_args, [ @_ ]; 24 return @{ shift @gai_rets }; 25}; 26 27@gai_rets = ( 28 [ "Service unknown" ], 29 [ "", { 30 family => PF_INET, 31 socktype => SOCK_STREAM, 32 protocol => IPPROTO_TCP, 33 addr => pack_sockaddr_in( 80, INADDR_ANY ) 34 } ], 35); 36 37IO::Socket::IP->new( LocalPort => "zyxxyblarg(80)" ); 38 39is_deeply( \@gai_args, 40 [ 41 [ undef, "zyxxyblarg", { flags => AI_PASSIVE|$AI_ADDRCONFIG, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], 42 [ undef, "80", { flags => AI_PASSIVE|$AI_ADDRCONFIG, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], 43 ], 44 '@gai_args for LocalPort => "zyxxyblarg(80)"' ); 45 46done_testing; 47