The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::DHCP::Config::Utilities::Options - Helper utilities for working with DHCP options.

VERSION

Version 0.0.1

SYNOPSIS

    use Net::DHCP::Config::Utilities::Options;
    
    my $dhcp_options=Net::DHCP::Config::Utilities::Options->new;
    
    my $options=$dhcp_options->get_options;
    use Data::Dumper;
    print Dumper( $options );

    my $error=$dhcp_options->validate_option( 'dns', '192.168.0.1 , 10.10.10.10' );
    if ( defined( $error ) ){
        die( $error );
    }

METHODS

new

Initiates the object.

    my $dhcp_options=Net::DHCP::Config::Utilities::Options->new;

get_code

Returns the DHCP code value for a option.

One option is taken and that is the option name.

If the option name is not found or is undef, then undef is returned.

    # you can use the long name
    print 'subnet-mask: '.$dhcp_options->get_code('subnet-mask')."\n";
    # or the easier to remember short name
    print 'mask: '.$dhcp_options->get_code('mask')."\n";

get_long

Returns the long option name for the specified option.

One argument is taken and that is the option name.

If the option name is not found or is undef, then undef is returned.

    print 'root: '.$dhcp_options->get_long('root')."\n";
    print 'mask: '.$dhcp_options->get_long('mask')."\n";
    print 'mtu: '.$dhcp_options->get_long('mtu')."\n";
    print 'routers: '.$dhcp_options->get_long('routers')."\n";

get_multiple

Returns if multiple values are supported by this option.

    0 = single value
    1 = multiple values

One option is taken and that is the option name.

If the option name is not found or is undef, then undef is returned.

    # you can use the long name
    print 'subnet-mask: '.$dhcp_options->get_multiple('subnet-mask')."\n";
    # or the easier to remember short name
    print 'mask: '.$dhcp_options->get_multiple('mask')."\n";

    if ( $dhcp_options->get_multiple('dns') ){
        print "Multiple values are supported... exanple\n".
              "10.10.10.1 , 10.10.10.2\n";
    }

get_options

Returns a hash ref with the various options.

    my $options=$dhcp_options->get_options;
    foreach my $opt ( keys( %{ $options } ) ){
        print "----\n".
              "option: ".$opt."\n".
              "code: ".$options->{$opt}{'code'}."\n".
              "multiple: ".$options->{$opt}{'multiple'}."\n".
              "type: ".$options->{$opt}{'type'}."\n".
              "long: ".$options->{$opt}{'long'}."\n".
    }

get_type

Returns the data type that the option in question is.

    ip  = IP address
    int = integer
    txt = text field that must be defined

One option is taken and that is the option name.

If the option name is not found or is undef, then undef is returned.

    print 'root: '.$dhcp_options->get_type('root')."\n";
    print 'mask: '.$dhcp_options->get_type('mask')."\n";
    print 'mtu: '.$dhcp_options->get_type('mtu')."\n";

valid_option_name

This checks if the option name is valid.

This checks for possible long and short forms.

    if ( ! $dhcp_options->valid_option_name( $option ) ){
        die( $option.' is not a valid option' );
    }

validate_options

This validates a option and the value for it.

Twu arguments are taken. The first is the option name and the third is the value.

If any issues are found a string is returned that describes it.

If there are no issues undef is returned.

This should not be mistaken for sanity checking. This just makes sure that the data is the correct type for the option.

    my $error=$dhcp_options->validate_option( $option, $value );
    if ( defined( $error ) ){
        die( $error );
    }

SUPPORT OPTIONS

This only supports the more commonly used one for now and avoids the out of date ones.

    | Code | Name             | Multi | Type | Long Name           |
    |------|------------------|-------|------|---------------------|
    | 0    | mask             | 0     | IP   | subnet-mask         |
    | 1    | time-offset      | 0     | INT  | time-offset         |
    | 3    | routers          | 1     | IP   | routers             |
    | 4    | ntp              | 1     | IP   | time-servers        |
    | 6    | dns              | 1     | IP   | domain-name-servers |
    | 17   | root             | 0     | TXT  | root-path           |
    | 26   | mtu              | 0     | INT  | interface-mtu       |
    | 28   | broadcast        | 0     | IP   | broadcast-address   |
    | 51   | lease-time       | 0     | INT  | dhcp-lease-time     |
    | 66   | tfp-server       | 0     | TXT  | next-server         |
    | 67   | bootfile         | 0     | TXT  | filename            |
    | 213  | v4-access-domain | 0     | TXT  | v4-access-domain    |
    | 252  | web-proxy        | 0     | TXT  | web-proxy           |

For options that can take multiple values, /\ *\,\ */ is used for the split.

Validation is done as below.

    INT = /^[0-9]+$/
    IP  = If Net::CIDR::addr2cidr can make sense of it.
    TXT = defined

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-net-dhcp-config-utilities at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-DHCP-Config-Utilities. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::DHCP::Config::Utilities

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)