恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装
Revision | 364aa4725a3a1f0a02d568aed9cc82bbe3723953 (tree) |
---|---|
Time | 2021-08-19 20:01:19 |
Author | dyknon <dyknon@user...> |
Commiter | dyknon |
Rewrite ipv6 address formatter
@@ -94,45 +94,12 @@ sub from_array { | ||
94 | 94 | # RFC5952 4. |
95 | 95 | sub str { |
96 | 96 | 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; | |
136 | 103 | } |
137 | 104 | |
138 | 105 | sub raw { |