File: 15io-socket.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (60 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use IO::Socket;
use IO::Socket::IP -register;

# AF_INET
{
   my $sock = IO::Socket->new(
      Domain    => AF_INET,
      Type      => SOCK_STREAM,
      LocalHost => "127.0.0.1",
      LocalPort => 0,
      GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG
   );

   isa_ok( $sock, [ "IO::Socket::IP" ], 'IO::Socket->new( Domain => AF_INET )' ) or
      diag( "  error was $IO::Socket::errstr" );

   $sock = IO::Socket->new(
      Domain    => AF_INET,
      Type      => SOCK_STREAM,
      LocalHost => "::1",
   );

   ok( !defined $sock, 'Domain => AF_INET, LocalHost => "::1" fails' );
}

SKIP: {
   my $AF_INET6 = eval { Socket::AF_INET6() } ||
                  eval { require Socket6; Socket6::AF_INET6() };
   $AF_INET6 or skip "No AF_INET6", 1;
   eval { IO::Socket::IP->new( LocalHost => "::1" ) } or
      skip "Unable to bind to ::1", 1;

   my $sock = IO::Socket->new(
      Domain    => $AF_INET6,
      Type      => SOCK_STREAM,
      LocalHost => "::1",
      LocalPort => 0,
      GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG
   );

   isa_ok( $sock, [ "IO::Socket::IP" ], 'IO::Socket->new( Domain => AF_INET6 )' ) or
      diag( "  error was $IO::Socket::errstr" );

   $sock = IO::Socket->new(
      Domain    => $AF_INET6,
      Type      => SOCK_STREAM,
      LocalHost => "127.0.0.1",
   );

   ok( !defined $sock, 'Domain => AF_INET6, LocalHost => "127.0.0.1" fails' );
}

done_testing;