xref: /openbsd-src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/06local-cross-v6.t (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8use IO::Socket::IP;
9
10eval { IO::Socket::IP->new( LocalHost => "::1" ) } or
11   plan skip_all => "Unable to bind to ::1";
12
13foreach my $socktype (qw( SOCK_STREAM SOCK_DGRAM )) {
14   my $testserver = IO::Socket::IP->new(
15      ( $socktype eq "SOCK_STREAM" ? ( Listen => 1 ) : () ),
16      LocalHost => "::1",
17      Type      => Socket->$socktype,
18   ) or die "Cannot listen on PF_INET6 - $@";
19
20   my $socket = IO::Socket::IP->new(
21      PeerHost    => "::1",
22      PeerService => $testserver->sockport,
23      Type        => Socket->$socktype,
24   ) or die "Cannot connect on PF_INET6 - $@";
25
26   my $testclient = ( $socktype eq "SOCK_STREAM" ) ?
27      $testserver->accept :
28      do { $testserver->connect( $socket->sockname ); $testserver };
29
30   is( $testclient->sockport, $socket->peerport, "\$testclient->sockport for $socktype" );
31   is( $testclient->peerport, $socket->sockport, "\$testclient->peerport for $socktype" );
32
33   is( $testclient->sockhost, $socket->peerhost, "\$testclient->sockhost for $socktype" );
34   is( $testclient->peerhost, $socket->sockhost, "\$testclient->peerhost for $socktype" );
35
36   $socket->write( "Request\n" );
37   is( $testclient->getline, "Request\n", "\$socket to \$testclient for $socktype" );
38
39   SKIP: {
40      skip "local DGRAM response fails on windows", 1 if $socktype eq 'SOCK_DGRAM' and $^O =~ /MSWin32|cygwin|msys/;
41
42      $testclient->write( "Response\n" );
43      is( $socket->getline, "Response\n", "\$testclient to \$socket for $socktype" );
44   }
45}
46
47done_testing;
48