1N/A#!./perl -w
1N/A
1N/ABEGIN {
1N/A if ($ENV{PERL_CORE}) {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A }
1N/A if (!eval "require Socket") {
1N/A print "1..0 # no Socket\n"; exit 0;
1N/A }
1N/A undef *{Socket::inet_aton};
1N/A undef *{Socket::inet_ntoa};
1N/A if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
1N/A print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
1N/A }
1N/A $INC{'Socket.pm'} = 1;
1N/A}
1N/A
1N/Apackage Socket;
1N/A
1N/Asub import {
1N/A my $pkg = caller();
1N/A no strict 'refs';
1N/A *{ $pkg . '::inet_aton' } = \&inet_aton;
1N/A *{ $pkg . '::inet_ntoa' } = \&inet_ntoa;
1N/A}
1N/A
1N/Amy $fail = 0;
1N/Amy %names;
1N/A
1N/Asub set_fail {
1N/A $fail = shift;
1N/A}
1N/A
1N/Asub inet_aton {
1N/A return if $fail;
1N/A my $num = unpack('N', pack('C*', split(/\./, $_[0])));
1N/A $names{$num} = $_[0];
1N/A return $num;
1N/A}
1N/A
1N/Asub inet_ntoa {
1N/A return if $fail;
1N/A return $names{$_[0]};
1N/A}
1N/A
1N/Apackage main;
1N/A
1N/A
1N/A(my $libnet_t = __FILE__) =~ s/config.t/libnet_t.pl/;
1N/Arequire $libnet_t;
1N/A
1N/Aprint "1..10\n";
1N/A
1N/Ause Net::Config;
1N/Aok( exists $INC{'Net/Config.pm'}, 'Net::Config should have been used' );
1N/Aok( keys %NetConfig, '%NetConfig should be imported' );
1N/A
1N/ASocket::set_fail(1);
1N/Aundef $NetConfig{'ftp_firewall'};
1N/Ais( Net::Config->requires_firewall(), 0,
1N/A 'requires_firewall() should return 0 without ftp_firewall defined' );
1N/A
1N/A$NetConfig{'ftp_firewall'} = 1;
1N/Ais( Net::Config->requires_firewall('a.host.not.there'), -1,
1N/A '... should return -1 without a valid hostname' );
1N/A
1N/ASocket::set_fail(0);
1N/Adelete $NetConfig{'local_netmask'};
1N/Ais( Net::Config->requires_firewall('127.0.0.1'), 0,
1N/A '... should return 0 without local_netmask defined' );
1N/A
1N/A$NetConfig{'local_netmask'} = '127.0.0.1/24';
1N/Ais( Net::Config->requires_firewall('127.0.0.1'), 0,
1N/A '... should return false if host is within netmask' );
1N/Ais( Net::Config->requires_firewall('192.168.10.0'), 1,
1N/A '... should return true if host is outside netmask' );
1N/A
1N/A# now try more netmasks
1N/A$NetConfig{'local_netmask'} = [ '127.0.0.1/24', '10.0.0.0/8' ];
1N/Ais( Net::Config->requires_firewall('10.10.255.254'), 0,
1N/A '... should find success with mutiple local netmasks' );
1N/Ais( Net::Config->requires_firewall('192.168.10.0'), 1,
1N/A '... should handle failure with multiple local netmasks' );
1N/A
1N/Ais( \&Net::Config::is_external, \&Net::Config::requires_firewall,
1N/A 'is_external() should be an alias for requires_firewall()' );