17gai-flags.t revision 1.1.1.2
1#!/usr/bin/perl 2 3use v5; 4use strict; 5use warnings; 6 7use Test::More; 8 9use IO::Socket::IP; 10use Socket 1.95 qw( 11 PF_INET SOCK_STREAM IPPROTO_TCP pack_sockaddr_in INADDR_ANY 12 AI_PASSIVE AI_NUMERICSERV 13); 14 15my $AI_ADDRCONFIG = eval { Socket::AI_ADDRCONFIG() } || 0; 16 17my @gai_args; 18my @gai_rets; 19 20no strict 'refs'; 21no warnings 'redefine'; 22 23*{"IO::Socket::IP::getaddrinfo"} = sub { 24 push @gai_args, [ @_ ]; 25 return @{ shift @gai_rets }; 26}; 27 28@gai_args = (); 29@gai_rets = ( 30 [ "", { 31 family => PF_INET, 32 socktype => SOCK_STREAM, 33 protocol => IPPROTO_TCP, 34 addr => pack_sockaddr_in( 80, INADDR_ANY ) 35 } ], 36); 37IO::Socket::IP->new( LocalPort => "80" ); 38 39is_deeply( \@gai_args, 40 [ 41 [ undef, "80", { flags => AI_PASSIVE|$AI_ADDRCONFIG, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], 42 ], 43 '@gai_args for LocalPort => "80"' ); 44 45SKIP: { 46 skip "No AI_NUMERICSERV", 1 unless defined eval { AI_NUMERICSERV() }; 47 48 @gai_args = (); 49 @gai_rets = ( 50 [ "", { 51 family => PF_INET, 52 socktype => SOCK_STREAM, 53 protocol => IPPROTO_TCP, 54 addr => pack_sockaddr_in( 80, INADDR_ANY ) 55 } ], 56 ); 57 IO::Socket::IP->new( LocalPort => "80", GetAddrInfoFlags => AI_NUMERICSERV ); 58 59 is_deeply( \@gai_args, 60 [ 61 [ undef, "80", { flags => AI_PASSIVE|AI_NUMERICSERV, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ], 62 ], 63 '@gai_args for LocalPort => "80", GetAddrInfoFlags => AI_NUMERICSERV' ); 64} 65 66done_testing; 67