| 1 | #!/usr/bin/false | ||
| 2 | # ABSTRACT: Client Link-Layer Address option (code 79) — link-layer type + address | ||
| 3 | # PODNAME: Net::DHCPv6::Option::ClientLinkLayerAddr | ||
| 4 | package Net::DHCPv6::Option::ClientLinkLayerAddr; | ||
| 5 | $Net::DHCPv6::Option::ClientLinkLayerAddr::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 'ClientLinkLayerAddr requires link_layer_type' unless defined $args{link_layer_type}; | ||
| 16 | croak 'ClientLinkLayerAddr requires link_layer_addr' unless defined $args{link_layer_addr}; | ||
| 17 | $args{code} = $OPTION_CLIENT_LINKLAYER_ADDR; | ||
| 18 | $args{data} = pack( 'n', $args{link_layer_type} ) . $args{link_layer_addr}; | ||
| 19 | my $self = $class->SUPER::new( %args ); | ||
| 20 | $self->{link_layer_type} = $args{link_layer_type}; | ||
| 21 | $self->{link_layer_addr} = $args{link_layer_addr}; | ||
| 22 | bless $self, $class; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub link_layer_type { shift->{link_layer_type} } | ||
| 26 | sub link_layer_addr { shift->{link_layer_addr} } | ||
| 27 | |||
| 28 | sub from_bytes_inner { | ||
| 29 | my ( $class, $code, $data ) = @_; | ||
| 30 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated ClientLinkLayerAddr option' ) | ||
| 31 | if CORE::length( $data ) < 3; | ||
| 32 | my $type = unpack( 'n', substr( $data, 0, 2 ) ); | ||
| 33 | my $addr = substr( $data, 2 ); | ||
| 34 | return $class->new( link_layer_type => $type, link_layer_addr => $addr ); | ||
| 35 | } | ||
| 36 | |||
| 37 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_CLIENT_LINKLAYER_ADDR} = __PACKAGE__; | ||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |