« blib/lib/Net/DHCPv6/Option/ClientLinkLayerAddr.pm
↑ Summary
blib/lib/Net/DHCPv6/Option/VendorOpts.pm »
| 1 | #!/usr/bin/false | ||
| 2 | # ABSTRACT: Remote ID option (code 37) — enterprise-number + opaque data | ||
| 3 | # PODNAME: Net::DHCPv6::Option::RemoteId | ||
| 4 | package Net::DHCPv6::Option::RemoteId; | ||
| 5 | $Net::DHCPv6::Option::RemoteId::VERSION = '0.001'; | ||
| 6 | use strictures 2; | ||
| 7 | use Carp qw(croak); | ||
| 8 | use Net::DHCPv6::Constants; | ||
| 9 | use Net::DHCPv6::X::Truncated; | ||
| 10 | use parent 'Net::DHCPv6::Option'; | ||
| 11 | use namespace::clean; | ||
| 12 | |||
| 13 | sub new { | ||
| 14 | my ( $class, %args ) = @_; | ||
| 15 | croak 'RemoteId requires enterprise_number' unless defined $args{enterprise_number}; | ||
| 16 | croak 'RemoteId requires remote_data' unless defined $args{remote_data}; | ||
| 17 | $args{code} = $OPTION_REMOTE_ID; | ||
| 18 | $args{data} = pack( 'N', $args{enterprise_number} ) . $args{remote_data}; | ||
| 19 | my $self = $class->SUPER::new( %args ); | ||
| 20 | $self->{enterprise_number} = $args{enterprise_number}; | ||
| 21 | $self->{remote_data} = $args{remote_data}; | ||
| 22 | bless $self, $class; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub enterprise_number { shift->{enterprise_number} } | ||
| 26 | sub remote_data { shift->{remote_data} } | ||
| 27 | |||
| 28 | sub from_bytes_inner { | ||
| 29 | my ( $class, $code, $data ) = @_; | ||
| 30 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated RemoteId option' ) | ||
| 31 | if CORE::length( $data ) < 4; | ||
| 32 | my $en = unpack( 'N', substr( $data, 0, 4 ) ); | ||
| 33 | my $rest = substr( $data, 4 ); | ||
| 34 | return $class->new( enterprise_number => $en, remote_data => $rest ); | ||
| 35 | } | ||
| 36 | |||
| 37 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_REMOTE_ID} = __PACKAGE__; | ||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |