#-*-perl-*- # # Copyright (c) 1997 Kevin Johnson . # Copyright (c) 2001 Rob Brown . # # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl # itself. # # $Id: Utils.pm,v 1.6 2002/04/18 02:22:47 rob Exp $ package Net::Bind::Utils; use strict; use vars qw($VERSION @ISA @EXPORT_OK); use Carp; use Exporter; $VERSION = '0.05'; @ISA = qw(Exporter); @EXPORT_OK = qw(valid_domain valid_domain_rfc1035 valid_ip valid_netmask); =head1 NAME Net::Bind::Utils - various routines common across Net::Bind packages. =head1 SYNOPSIS use Net::Bind::Utils qw(valid_domain valid_ip); =head1 DESCRIPTION A catch-all place for various routines that are useful across most, if not all, of the C interfaces. This module is not designed to be subclassable. =head1 ROUTINES =head2 valid_domain($domain) Returns C<1> if the given C<$domain> string is defined and is a domain that bind is capable of resolving, otherwise returns C<0>. =cut sub valid_domain { my $domain = shift; return 0 unless defined($domain); # Root domain is okay return 1 if $domain eq "."; # empty label is illegal return 0 if $domain =~ /\.\./; # Force rooting if not already done $domain =~ s/([^\.])$/$1./; # A preceeding "-" in any section is illegal return 0 if $domain =~ /(^|\.)\-/; # A trailing "-" in any section is illegal return 0 if $domain =~ /\-\./; # Make sure each section has between 1 and 63 characters return 1 if $domain =~ /^([a-zA-Z0-9\-]{1,63}\.)+$/; return 0; } =head2 valid_domain_rfc1035($domain) Returns C<1> if the given C<$domain> string is defined and is a valid rfc1035 domain name, otherwise returns C<0>. =cut sub valid_domain_rfc1035 { my $domain = shift; return 0 unless defined($domain); # from RFC1035: # ::= | " " # ::=