1#!perl 2 3use 5.008001; 4 5use strict; 6use warnings; 7 8use Test::More; 9 10BEGIN { 11 if (!eval { require Socket }) { 12 plan skip_all => "no Socket"; 13 } 14 elsif (ord('A') == 193 && !eval { require Convert::EBCDIC }) { 15 plan skip_all => "EBCDIC but no Convert::EBCDIC"; 16 } 17} 18 19use Config; 20use File::Temp 'tempfile'; 21use Net::NNTP; 22 23my $debug = 0; # Net::NNTP->new( Debug => .. ) 24 25my $inet6class = Net::NNTP->can_inet6; 26plan skip_all => "no IPv6 support found in Net::NNTP" if ! $inet6class; 27 28plan skip_all => "fork not supported on this platform" 29 unless $Config::Config{d_fork} || $Config::Config{d_pseudofork} || 30 (($^O eq 'MSWin32' || $^O eq 'NetWare') and 31 $Config::Config{useithreads} and 32 $Config::Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/); 33 34my $srv = $inet6class->new( 35 LocalAddr => '::1', 36 Listen => 10 37); 38plan skip_all => "cannot create listener on ::1: $!" if ! $srv; 39my $host = $srv->sockhost; 40my $port = $srv->sockport; 41note("server on $host port $port"); 42 43plan tests => 1; 44 45defined( my $pid = fork()) or die "fork failed: $!"; 46exit(nntp_server()) if ! $pid; 47 48my $cl = Net::NNTP->new(Host => $host, Port => $port,, Debug => $debug); 49note("created Net::NNTP object"); 50if (!$cl) { 51 fail("IPv6 NNTP connect failed"); 52} else { 53 $cl->quit; 54 pass("IPv6 success"); 55} 56wait; 57 58sub nntp_server { 59 my $ssl = shift; 60 my $cl = $srv->accept or die "accept failed: $!"; 61 print $cl "200 nntp.example.com\r\n"; 62 while (<$cl>) { 63 my ($cmd,$arg) = m{^(\S+)(?: +(.*))?\r\n} or die $_; 64 $cmd = uc($cmd); 65 if ($cmd eq 'QUIT' ) { 66 print $cl "205 bye\r\n"; 67 last; 68 } elsif ( $cmd eq 'MODE' ) { 69 print $cl "201 Posting denied\r\n"; 70 } else { 71 diag("received unknown command: $cmd"); 72 print "500 unknown cmd\r\n"; 73 } 74 } 75 note("NNTP dialog done"); 76 return 0; 77} 78