sub isPlainHostName {
my ($host) = @_;
return (($host =~ /\./) ? 0 : 1);
}
##############################################################################
#
# dnsDomainIs - PAC command to tell if the host is in the domain.
#
##############################################################################
sub dnsDomainIs {
my ($host,$domain) = @_;
$domain =~ s/\./\\\./;
return (($host =~ /$domain$/) ? 1 : 0);
}
##############################################################################
#
# localHostOrDomainIs - PAC command to tell if the host matches, or if it is
# unqaulifed and in the domain.
#
##############################################################################
sub localHostOrDomainIs {
my ($host,$hostdom) = @_;
return 1 if ($host eq $hostdom);
return 0 if ($host =~ /\./);
return 1 if ($hostdom =~ /^$host/);
}
##############################################################################
#
# isResolvable - PAC command to see if the host can be resolved via DNS.
#
##############################################################################
sub isResolvable {
my ($host) = @_;
return (defined(gethostbyname($host)) ? 1 : 0);
}
##############################################################################
#
# isInNet - PAC command to see if the IP address is in this network based on
# the mask and pattern.
#
##############################################################################
sub isInNet {
my ($host,$pattern,$mask) = @_;
my $addr = dnsResolve($host);
return unless defined($addr);
my @addr = split(/\./,$addr);
my @mask = split(/\./,$mask);
my @pattern;
foreach my $count (0..3) {
my $bitAddr = dec2bin($addr[$count]);
my $bitMask = dec2bin($mask[$count]);
$pattern[$count] = bin2dec($bitAddr & $bitMask),"\n";
}
my $hostPattern = join(".",@pattern);
return (($pattern eq $hostPattern) ? 1 : 0);
}
##############################################################################
#
# dec2bin - decimal to binary conversion
#
##############################################################################
sub dec2bin {
my $str = unpack("B32", pack("N", shift));
return $str;
}
##############################################################################
#
# bin2dec - binary to decimal conversion
#
##############################################################################
sub bin2dec {
return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
}
##############################################################################
#
# dnsResolve - PAC command to get the IP from the host name.
#
##############################################################################
=4= |