<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Net::Config.pm
#
# Copyright (C) 2000 Graham Barr.  All rights reserved.
# Copyright (C) 2013-2014, 2016, 2020 Steve Hay.  All rights reserved.
# This module is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself, i.e. under the terms of either the GNU General
# Public License or the Artistic License, as specified in the F&lt;LICENCE&gt; file.

package Net::Config;

use 5.008001;

use strict;
use warnings;

use Exporter;
use Socket qw(inet_aton inet_ntoa);

our @EXPORT  = qw(%NetConfig);
our @ISA     = qw(Net::LocalCfg Exporter);
our $VERSION = "3.15";

our($CONFIGURE, $LIBNET_CFG);

eval {
  local @INC = @INC;
  pop @INC if $INC[-1] eq '.';
  local $SIG{__DIE__};
  require Net::LocalCfg;
};

our %NetConfig = (
  nntp_hosts      =&gt; [],
  snpp_hosts      =&gt; [],
  pop3_hosts      =&gt; [],
  smtp_hosts      =&gt; [],
  ph_hosts        =&gt; [],
  daytime_hosts   =&gt; [],
  time_hosts      =&gt; [],
  inet_domain     =&gt; undef,
  ftp_firewall    =&gt; undef,
  ftp_ext_passive =&gt; 1,
  ftp_int_passive =&gt; 1,
  test_hosts      =&gt; 1,
  test_exist      =&gt; 1,
);

#
# Try to get as much configuration info as possible from InternetConfig
#
{
## no critic (BuiltinFunctions::ProhibitStringyEval)
$^O eq 'MacOS' and eval &lt;&lt;TRY_INTERNET_CONFIG;
use Mac::InternetConfig;

{
my %nc = (
    nntp_hosts      =&gt; [ \$InternetConfig{ kICNNTPHost() } ],
    pop3_hosts      =&gt; [ \$InternetConfig{ kICMailAccount() } =~ /\@(.*)/ ],
    smtp_hosts      =&gt; [ \$InternetConfig{ kICSMTPHost() } ],
    ftp_testhost    =&gt; \$InternetConfig{ kICFTPHost() } ? \$InternetConfig{ kICFTPHost()} : undef,
    ph_hosts        =&gt; [ \$InternetConfig{ kICPhHost() }   ],
    ftp_ext_passive =&gt; \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
    ftp_int_passive =&gt; \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
    socks_hosts     =&gt; 
        \$InternetConfig{ kICUseSocks() }    ? [ \$InternetConfig{ kICSocksHost() }    ] : [],
    ftp_firewall    =&gt; 
        \$InternetConfig{ kICUseFTPProxy() } ? [ \$InternetConfig{ kICFTPProxyHost() } ] : [],
);
\@NetConfig{keys %nc} = values %nc;
}
TRY_INTERNET_CONFIG
}

my $file = __FILE__;
my $ref;
$file =~ s/Config.pm/libnet.cfg/;
if (-f $file) {
  $ref = eval { local $SIG{__DIE__}; do $file };
  if (ref($ref) eq 'HASH') {
    %NetConfig = (%NetConfig, %{$ref});
    $LIBNET_CFG = $file;
  }
}
if ($&lt; == $&gt; and !$CONFIGURE) {
  my $home = eval { local $SIG{__DIE__}; (getpwuid($&gt;))[7] } || $ENV{HOME};
  $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH} || '') if defined $ENV{HOMEDRIVE};
  if (defined $home) {
    $file      = $home . "/.libnetrc";
    $ref       = eval { local $SIG{__DIE__}; do $file } if -f $file;
    %NetConfig = (%NetConfig, %{$ref})
      if ref($ref) eq 'HASH';
  }
}
my ($k, $v);
while (($k, $v) = each %NetConfig) {
  $NetConfig{$k} = [$v]
    if ($k =~ /_hosts$/ and $k ne "test_hosts" and defined($v) and !ref($v));
}

# Take a hostname and determine if it is inside the firewall


sub requires_firewall {
  shift;    # ignore package
  my $host = shift;

  return 0 unless defined $NetConfig{'ftp_firewall'};

  $host = inet_aton($host) or return -1;
  $host = inet_ntoa($host);

  if (exists $NetConfig{'local_netmask'}) {
    my $quad = unpack("N", pack("C*", split(/\./, $host)));
    my $list = $NetConfig{'local_netmask'};
    $list = [$list] unless ref($list);
    foreach (@$list) {
      my ($net, $bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next;
      my $mask = ~0 &lt;&lt; (32 - $bits);
      my $addr = unpack("N", pack("C*", split(/\./, $net)));

      return 0 if (($addr &amp; $mask) == ($quad &amp; $mask));
    }
    return 1;
  }

  return 0;
}

*is_external = \&amp;requires_firewall;

1;

__END__

=head1 NAME

Net::Config - Local configuration data for libnet

=head1 SYNOPSIS

    use Net::Config qw(%NetConfig);

=head1 DESCRIPTION

C&lt;Net::Config&gt; holds configuration data for the modules in the libnet
distribution. During installation you will be asked for these values.

The configuration data is held globally in a file in the perl installation
tree, but a user may override any of these values by providing their own. This
can be done by having a C&lt;.libnetrc&gt; file in their home directory. This file
should return a reference to a HASH containing the keys described below.
For example

    # .libnetrc
    {
        nntp_hosts =&gt; [ "my_preferred_host" ],
        ph_hosts   =&gt; [ "my_ph_server" ],
    }
    __END__

=head2 Class Methods

C&lt;Net::Config&gt; defines the following methods. They are methods as they are
invoked as class methods. This is because C&lt;Net::Config&gt; inherits from
C&lt;Net::LocalCfg&gt; so you can override these methods if you want.

=over 4

=item C&lt;requires_firewall($host)&gt;

Attempts to determine if a given host is outside your firewall. Possible
return values are.

  -1  Cannot lookup hostname
   0  Host is inside firewall (or there is no ftp_firewall entry)
   1  Host is outside the firewall

This is done by using hostname lookup and the C&lt;local_netmask&gt; entry in
the configuration data.

=back

=head2 NetConfig Values

=over 4

=item nntp_hosts

=item snpp_hosts

=item pop3_hosts

=item smtp_hosts

=item ph_hosts

=item daytime_hosts

=item time_hosts

Each is a reference to an array of hostnames (in order of preference),
which should be used for the given protocol

=item inet_domain

Your internet domain name

=item ftp_firewall

If you have an FTP proxy firewall (B&lt;NOT&gt; an HTTP or SOCKS firewall)
then this value should be set to the firewall hostname. If your firewall
does not listen to port 21, then this value should be set to
C&lt;"hostname:port"&gt; (eg C&lt;"hostname:99"&gt;)

=item ftp_firewall_type

There are many different ftp firewall products available. But unfortunately
there is no standard for how to traverse a firewall.  The list below shows the
sequence of commands that Net::FTP will use

  user        Username for remote host
  pass        Password for remote host
  fwuser      Username for firewall
  fwpass      Password for firewall
  remote.host The hostname of the remote ftp server

=over 4

=item 0Z&lt;&gt;

There is no firewall

=item 1Z&lt;&gt;

     USER user@remote.host
     PASS pass

=item 2Z&lt;&gt;

     USER fwuser
     PASS fwpass
     USER user@remote.host
     PASS pass

=item 3Z&lt;&gt;

     USER fwuser
     PASS fwpass
     SITE remote.site
     USER user
     PASS pass

=item 4Z&lt;&gt;

     USER fwuser
     PASS fwpass
     OPEN remote.site
     USER user
     PASS pass

=item 5Z&lt;&gt;

     USER user@fwuser@remote.site
     PASS pass@fwpass

=item 6Z&lt;&gt;

     USER fwuser@remote.site
     PASS fwpass
     USER user
     PASS pass

=item 7Z&lt;&gt;

     USER user@remote.host
     PASS pass
     AUTH fwuser
     RESP fwpass

=back

=item ftp_ext_passive

=item ftp_int_passive

FTP servers can work in passive or active mode. Active mode is when
you want to transfer data you have to tell the server the address and
port to connect to.  Passive mode is when the server provide the
address and port and you establish the connection.

With some firewalls active mode does not work as the server cannot
connect to your machine (because you are behind a firewall) and the firewall
does not re-write the command. In this case you should set C&lt;ftp_ext_passive&gt;
to a I&lt;true&gt; value.

Some servers are configured to only work in passive mode. If you have
one of these you can force C&lt;Net::FTP&gt; to always transfer in passive
mode; when not going via a firewall, by setting C&lt;ftp_int_passive&gt; to
a I&lt;true&gt; value.

=item local_netmask

A reference to a list of netmask strings in the form C&lt;"134.99.4.0/24"&gt;.
These are used by the C&lt;requires_firewall&gt; function to determine if a given
host is inside or outside your firewall.

=back

The following entries are used during installation &amp; testing on the
libnet package

=over 4

=item test_hosts

If true then C&lt;make test&gt; may attempt to connect to hosts given in the
configuration.

=item test_exists

If true then C&lt;Configure&gt; will check each hostname given that it exists

=back

=head1 EXPORTS

The following symbols are, or can be, exported by this module:

=over 4

=item Default Exports

C&lt;%NetConfig&gt;.

=item Optional Exports

I&lt;None&gt;.

=item Export Tags

I&lt;None&gt;.

=back

=head1 KNOWN BUGS

I&lt;None&gt;.

=head1 AUTHOR

Graham Barr E&lt;lt&gt;L&lt;gbarr@pobox.com|mailto:gbarr@pobox.com&gt;E&lt;gt&gt;.

Steve Hay E&lt;lt&gt;L&lt;shay@cpan.org|mailto:shay@cpan.org&gt;E&lt;gt&gt; is now maintaining
libnet as of version 1.22_02.

=head1 COPYRIGHT

Copyright (C) 2000 Graham Barr.  All rights reserved.

Copyright (C) 2013-2014, 2016, 2020 Steve Hay.  All rights reserved.

=head1 LICENCE

This module is free software; you can redistribute it and/or modify it under the
same terms as Perl itself, i.e. under the terms of either the GNU General Public
License or the Artistic License, as specified in the F&lt;LICENCE&gt; file.

=head1 VERSION

Version 3.15

=head1 DATE

20 March 2023

=head1 HISTORY

See the F&lt;Changes&gt; file.

=cut
</pre></body></html>