• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装


Commit MetaInfo

Revision364aa4725a3a1f0a02d568aed9cc82bbe3723953 (tree)
Time2021-08-19 20:01:19
Authordyknon <dyknon@user...>
Commiterdyknon

Log Message

Rewrite ipv6 address formatter

Change Summary

Incremental Difference

--- a/Net/DHCP6/Value/Ipv6Addr.pm
+++ b/Net/DHCP6/Value/Ipv6Addr.pm
@@ -94,45 +94,12 @@ sub from_array {
9494 # RFC5952 4.
9595 sub str {
9696 my $self = shift;
97- my @parts = unpack "S>*", $$self;
98-
99- my $start_mzeros;
100- my $length_mzeros = 0;
101- {
102- my $start_zeros;
103- my $length_zeros = 0;
104- while(my ($i, $v) = each(@parts)){
105- if($v){
106- if($length_zeros > $length_mzeros){
107- $start_mzeros = $start_zeros;
108- $length_mzeros = $length_zeros;
109- }
110- $length_zeros = 0;
111- }else{
112- if($length_zeros++ == 0){
113- $start_zeros = $i;
114- }
115- }
116- }
117- if($length_zeros > $length_mzeros){
118- $start_mzeros = $start_zeros;
119- $length_mzeros = $length_zeros;
120- }
121- }
122-
123- @parts = map{sprintf "%x", $_} @parts;
124- if($length_mzeros > 1){
125- my $i1 = $start_mzeros - 1;
126- my $i2 = $start_mzeros + $length_mzeros;
127- @parts = (@parts[0..$i1], "", @parts[$i2..$#parts]);
128- }
129- if($parts[0] eq ""){
130- unshift @parts, "";
131- }
132- if($parts[$#parts] eq ""){
133- push @parts, "";
134- }
135- join(":", @parts);
97+ my $str = join "", map{chr $_} unpack("S>*", $$self);
98+ $str =~ s/(\0\0++)(?!.*\0\1)/\x{10000}/;
99+ $str =~ s/(.)/$1 eq "\x{10000}" ? "@" : sprintf("%x:", ord($1))/ge;
100+ $str =~ s/:$//;
101+ $str =~ s/:?@/::/;
102+ $str;
136103 }
137104
138105 sub raw {