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