pop3_ipv6.t revision 1.2
1#!perl
2
3use 5.008001;
4
5use strict;
6use warnings;
7
8use Config;
9use File::Temp 'tempfile';
10use Net::POP3;
11use Test::More;
12
13my $debug = 0; # Net::POP3->new( Debug => .. )
14
15my $inet6class = Net::POP3->can_inet6;
16plan skip_all => "no IPv6 support found in Net::POP3" if ! $inet6class;
17
18plan skip_all => "fork not supported on this platform"
19  unless $Config::Config{d_fork} || $Config::Config{d_pseudofork} ||
20    (($^O eq 'MSWin32' || $^O eq 'NetWare') and
21     $Config::Config{useithreads} and
22     $Config::Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/);
23
24my $srv = $inet6class->new(
25  LocalAddr => '::1',
26  Listen => 10
27);
28plan skip_all => "cannot create listener on ::1: $!" if ! $srv;
29my $saddr = "[".$srv->sockhost."]".':'.$srv->sockport;
30note("server on $saddr");
31
32plan tests => 1;
33
34defined( my $pid = fork()) or die "fork failed: $!";
35exit(pop3_server()) if ! $pid;
36
37my $cl = Net::POP3->new($saddr, Debug => $debug);
38note("created Net::POP3 object");
39if (!$cl) {
40  fail("IPv6 POP3 connect failed");
41} else {
42  $cl->quit;
43  pass("IPv6 success");
44}
45wait;
46
47sub pop3_server {
48  my $cl = $srv->accept or die "accept failed: $!";
49  print $cl "+OK localhost ready\r\n";
50  while (<$cl>) {
51    my ($cmd,$arg) = m{^(\S+)(?: +(.*))?\r\n} or die $_;
52    $cmd = uc($cmd);
53    if ($cmd eq 'QUIT' ) {
54      print $cl "+OK bye\r\n";
55      last;
56    } elsif ( $cmd eq 'CAPA' ) {
57      print $cl "+OK\r\n".
58        ".\r\n";
59    } else {
60      diag("received unknown command: $cmd");
61      print "-ERR unknown cmd\r\n";
62    }
63  }
64
65  note("POP3 dialog done");
66  return 0;
67}
68