恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装
修訂 | 9b7108f06524751cd2d59521a550dcd5b92639e1 (tree) |
---|---|
時間 | 2021-08-12 22:21:25 |
作者 | dyknon <dyknon@user...> |
Commiter | dyknon |
emit error if unparsed option is required by class
@@ -28,8 +28,16 @@ sub options { | ||
28 | 28 | %index = (%index, |
29 | 29 | map{$_, 1}grep{$opts[$_]->code == $key}(0 .. $#opts)); |
30 | 30 | }else{ |
31 | - %index = (%index, | |
32 | - map{$_, 1}grep{$opts[$_]->isa($key)}(0 .. $#opts)); | |
31 | + my $code = eval{$key->code}; | |
32 | + my %hits = map{$_, 1}grep{$opts[$_]->isa($key)}(0 .. $#opts); | |
33 | + if(defined $code){ | |
34 | + my $error = join "", | |
35 | + grep{!exists $hits{$_}} | |
36 | + grep{$opts[$_]->code == $code} | |
37 | + (0 .. $#opts); | |
38 | + die "the required option is left unparsed" if($error); | |
39 | + } | |
40 | + %index = (%index, %hits); | |
33 | 41 | } |
34 | 42 | } |
35 | 43 | @opts[keys %index]; |
@@ -50,14 +50,14 @@ my $client = Net::DHCP6::Exchange::InfoReq->new( | ||
50 | 50 | DHCP6_OPT_DNS_SERVERS, |
51 | 51 | ], |
52 | 52 | failed => sub{print("timeout\n");}, |
53 | - recved => sub{ | |
53 | + recved => sub{ eval{ | |
54 | 54 | my $recved = shift; |
55 | 55 | print("message: $recved\n"); |
56 | - for($recved->option(DHCP6_OPT_DNS_SERVERS)->all_elems){ | |
56 | + for($recved->option("Net::DHCP6::Option::DnsServer")->all_elems){ | |
57 | 57 | print("DNS-server: $_\n"); |
58 | 58 | } |
59 | 59 | 1; |
60 | - }, | |
60 | + }}, | |
61 | 61 | ); |
62 | 62 | |
63 | 63 | local $| = 1; |