I don't want garbage config to munge to "" to 0 to 0.0.0.0 resulting in a worst case in passwords being advertised all interfaces. Probably re-inventing the wheel but...
my $dotted_quad_ipv4_host = sub {
my ( $ip , $i , @dots ) = ( "" , 0 , 0 ) ;
map { $ip =
(
( length ( $_ ) ) and
( ++$i < 5 ) and
( $_ >= 0 ) and
( $_ <= 255 ) and
(
( length ( $_ ) == 1 ) or
( length ( $_ ) > 1 and int substr ( $_ , 0 , 1 ) > 0 )
) and
(
( $i == 1 and $_ > 0 ) or
( $i == 2 ) or
( $i == 3 ) or
( $i == 4 and $_ > 0 )
)
)
? ( ( $ip ) ? $ip . "." . $_ : $_ )
: "" ;
} split ( /[^0-9]+/ , shift ) ;
( @dots ) = ( split /[^.]+/ , $ip ) if index ( $ip , '.' ) ;
return ( $ip ) if $#dots == 3 ;
} ;#___________tests__________
print "\n" . $dotted_quad_ipv4_host->(' x #comment127.0.0.1 #comment ') ; # print "\n" . $dotted_quad_ipv4_host->(' x #comment027.0.9.1 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->(' x #comment027.0.09.1 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->(' x #comment127.0.999.1 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->(' x #comment127.0.0.0 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->(' x #comment255.255.255.255 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->('255.255.255.255') ;
print "\n" . $dotted_quad_ipv4_host->(' x #comment0.0.0.0 #comment ') ;
print "\n" . $dotted_quad_ipv4_host->('0.0.0.0') ;
-Bob Dodds
