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::SMTP; 22 23my $debug = 0; # Net::SMTP->new( Debug => .. ) 24 25my $inet6class = Net::SMTP->can_inet6; 26plan skip_all => "no IPv6 support found in Net::SMTP" 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 $saddr = "[".$srv->sockhost."]".':'.$srv->sockport; 40note("server on $saddr"); 41 42plan tests => 1; 43 44defined( my $pid = fork()) or die "fork failed: $!"; 45exit(smtp_server()) if ! $pid; 46 47my $cl = Net::SMTP->new($saddr, Debug => $debug); 48note("created Net::SMTP object"); 49if (!$cl) { 50 fail("IPv6 SMTP connect failed"); 51} else { 52 $cl->quit; 53 pass("IPv6 success"); 54} 55wait; 56 57sub smtp_server { 58 my $cl = $srv->accept or die "accept failed: $!"; 59 print $cl "220 welcome\r\n"; 60 while (<$cl>) { 61 my ($cmd,$arg) = m{^(\S+)(?: +(.*))?\r\n} or die $_; 62 $cmd = uc($cmd); 63 if ($cmd eq 'QUIT' ) { 64 print $cl "250 bye\r\n"; 65 last; 66 } elsif ( $cmd eq 'HELO' ) { 67 print $cl "250 localhost\r\n"; 68 } elsif ( $cmd eq 'EHLO' ) { 69 print $cl "250-localhost\r\n". 70 "250 HELP\r\n"; 71 } else { 72 diag("received unknown command: $cmd"); 73 print "500 unknown cmd\r\n"; 74 } 75 } 76 77 note("SMTP dialog done"); 78 return 0; 79} 80