File: 17gai-flags.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (65 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use IO::Socket::IP;
use Socket 1.95 qw(
   PF_INET SOCK_STREAM IPPROTO_TCP pack_sockaddr_in INADDR_ANY
   AI_PASSIVE AI_NUMERICSERV
);

my $AI_ADDRCONFIG = eval { Socket::AI_ADDRCONFIG() } || 0;

my @gai_args;
my @gai_rets;

no strict 'refs';
no warnings 'redefine';

*{"IO::Socket::IP::getaddrinfo"} = sub {
   push @gai_args, [ @_ ];
   return @{ shift @gai_rets };
};

@gai_args = ();
@gai_rets = (
   [ "", {
         family   => PF_INET,
         socktype => SOCK_STREAM,
         protocol => IPPROTO_TCP,
         addr     => pack_sockaddr_in( 80, INADDR_ANY )
      } ],
);
IO::Socket::IP->new( LocalPort => "80" );

is_deeply( \@gai_args,
           [ 
              [ undef, "80", { flags => AI_PASSIVE|$AI_ADDRCONFIG, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ],
           ],
           '@gai_args for LocalPort => "80"' );

SKIP: {
   skip "No AI_NUMERICSERV", 1 unless defined eval { AI_NUMERICSERV() };

   @gai_args = ();
   @gai_rets = (
      [ "", {
            family   => PF_INET,
            socktype => SOCK_STREAM,
            protocol => IPPROTO_TCP,
            addr     => pack_sockaddr_in( 80, INADDR_ANY )
         } ],
   );
   IO::Socket::IP->new( LocalPort => "80", GetAddrInfoFlags => AI_NUMERICSERV );

   is_deeply( \@gai_args,
              [ 
                 [ undef, "80", { flags => AI_PASSIVE|AI_NUMERICSERV, socktype => SOCK_STREAM, protocol => IPPROTO_TCP } ],
              ],
              '@gai_args for LocalPort => "80", GetAddrInfoFlags => AI_NUMERICSERV' );
}

done_testing;