construqt-ipaddress 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68efedd1ed7a0b49fcdafe4dad0b34d00208c11c
4
- data.tar.gz: e8e4ede0555891a4c3852b5bd3780494338ab045
3
+ metadata.gz: 09666181f499c798901477f5738ac611ccf0537b
4
+ data.tar.gz: dbfe66242c03ed3c997437111c258f3e90e587a5
5
5
  SHA512:
6
- metadata.gz: 758df94417d927ecb6eacd4a5b904852f04ee16f66c517f5ec39751424d9e8b385acc53b3f3878903e61ae88db913e4515236e4f12f6242825c08ec471186434
7
- data.tar.gz: 01c2c1db4efdb0bd9a93f2e18dd75297ac8971f905c1ce1e24fbd3fbdf1c942a969caa7dd8ef6ddac31975cae19d7d8e31fbb6180f481af02af86e228af61d72
6
+ metadata.gz: ac36fc4db7a36cb89397e2533a15eb061b488043fe30d47a1b47c12dbfc226ee2eede0ce97016a3653ed3956d2b4ae14b3dfa6749415c9d883e9ae78aff9f915
7
+ data.tar.gz: f1e505af7cb8e2ea958f4e79cbdc656e085e8af97efa366c78df9654b949a38032a478cae82a1f7c6ed6ec5250f7fdb8a28f4f0d51c865b0dde869a0dd67df1a
data/ipaddress.gemspec CHANGED
@@ -5,8 +5,9 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{construqt-ipaddress}
8
- s.version = "0.8.2"
8
+ s.version = "0.8.4"
9
9
 
10
+ s.license = "Simple from Marco Ceresa"
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
12
  s.authors = ["Marco Ceresa", "Meno Abels"]
12
13
  s.date = %q{2014-11-29}
@@ -327,12 +327,9 @@ module IPAddress;
327
327
  # #=> ["e.ip6.arpa", "f.ip6.arpa"]
328
328
  #
329
329
  def rev_domains
330
- ret = []
331
- network = IPv6.parse_u128(network_u128, [(@prefix.to_i/4)*4 + 3, 123].min)
332
- network.each_net do |net|
333
- ret << net.reverse[(128-(net.prefix.to_i))/4*2..-1]
330
+ network.four_bit_networks.map do |net|
331
+ net.reverse[(128-(net.prefix.to_i))/4*2..-1]
334
332
  end
335
- ret
336
333
  end
337
334
 
338
335
 
@@ -483,12 +480,21 @@ module IPAddress;
483
480
  # WARNING: if the host portion is very large, this method
484
481
  # can be very slow and possibly hang your system!
485
482
  #
486
- def each_net
487
- start = network_u128
488
- while (@prefix.host_prefix.to_i-1) > 0 && start < broadcast_u128
489
- yield self.class.parse_u128(start, @prefix)
490
- start += 1<<(@prefix.host_prefix.to_i-1)
483
+ # There is a symantic problem i will now
484
+ # decide how network work in ipv6
485
+ def four_bit_networks
486
+ step = network_u128
487
+ next_four_bit_mask = ((@prefix.to_i+3)/4)*4
488
+ return [network] if next_four_bit_mask <= 0
489
+ step_four_bit_net = 1<<(128-next_four_bit_mask)
490
+ return [network] if step_four_bit_net == 0
491
+ ret = []
492
+ while step <= broadcast_u128
493
+ #puts "%s %x=>%x/%d"%[to_string, step,step_four_bit_net,next_four_bit_mask]
494
+ ret << self.class.parse_u128(step, next_four_bit_mask)
495
+ step += step_four_bit_net
491
496
  end
497
+ ret
492
498
  end
493
499
 
494
500
  #
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
-
2
+
3
3
  class IPv6Test < Test::Unit::TestCase
4
-
4
+
5
5
  def setup
6
6
  @klass = IPAddress::IPv6
7
-
8
- @compress_addr = {
7
+
8
+ @compress_addr = {
9
9
  "2001:db8:0000:0000:0008:0800:200c:417a" => "2001:db8::8:800:200c:417a",
10
10
  "2001:db8:0:0:8:800:200c:417a" => "2001:db8::8:800:200c:417a",
11
11
  "ff01:0:0:0:0:0:0:101" => "ff01::101",
@@ -30,7 +30,7 @@ class IPv6Test < Test::Unit::TestCase
30
30
  "::/0" => 0,
31
31
  "1080:0:0:0:8:800:200C:417A" => 21932261930451111902915077091070067066,
32
32
  "1080::8:800:200C:417A" => 21932261930451111902915077091070067066}
33
-
33
+
34
34
  @invalid_ipv6 = [":1:2:3:4:5:6:7",
35
35
  ":1:2:3:4:5:6:7",
36
36
  "2002:516:2:200",
@@ -40,13 +40,13 @@ class IPv6Test < Test::Unit::TestCase
40
40
  "2001:db8:1:1:1:1:1:1/32" => "2001:db8::/32",
41
41
  "2001:db8:1:1:1:1:1::/32" => "2001:db8::/32",
42
42
  "2001:db8::1/64" => "2001:db8::/64"}
43
-
43
+
44
44
  @ip = @klass.new "2001:db8::8:800:200c:417a/64"
45
45
  @network = @klass.new "2001:db8:8:800::/64"
46
46
  @arr = [8193,3512,0,0,8,2048,8204,16762]
47
47
  @hex = "20010db80000000000080800200c417a"
48
48
  end
49
-
49
+
50
50
  def test_attribute_address
51
51
  addr = "2001:0db8:0000:0000:0008:0800:200c:417a"
52
52
  assert_equal addr, @ip.address
@@ -66,7 +66,7 @@ class IPv6Test < Test::Unit::TestCase
66
66
  @klass.new "::10.1.1.1"
67
67
  }
68
68
  end
69
-
69
+
70
70
  def test_attribute_groups
71
71
  assert_equal @arr, @ip.groups
72
72
  end
@@ -75,7 +75,7 @@ class IPv6Test < Test::Unit::TestCase
75
75
  arr = "2001:0db8:0000:0000:0008:0800:200c:417a".split(":")
76
76
  assert_equal arr, @ip.hexs
77
77
  end
78
-
78
+
79
79
  def test_method_to_i
80
80
  @valid_ipv6.each do |ip,num|
81
81
  assert_equal num, @klass.new(ip).to_i
@@ -84,7 +84,7 @@ class IPv6Test < Test::Unit::TestCase
84
84
 
85
85
  def test_method_bits
86
86
  bits = "0010000000000001000011011011100000000000000000000" +
87
- "000000000000000000000000000100000001000000000000010000" +
87
+ "000000000000000000000000000100000001000000000000010000" +
88
88
  "0000011000100000101111010"
89
89
  assert_equal bits, @ip.bits
90
90
  end
@@ -117,7 +117,7 @@ class IPv6Test < Test::Unit::TestCase
117
117
  def test_method_ipv4?
118
118
  assert_equal false, @ip.ipv4?
119
119
  end
120
-
120
+
121
121
  def test_method_ipv6?
122
122
  assert_equal true, @ip.ipv6?
123
123
  end
@@ -153,7 +153,7 @@ class IPv6Test < Test::Unit::TestCase
153
153
  not_included = @klass.new "2001:db8::8:800:200c:417a/46"
154
154
  assert_equal true, @ip.include?(included)
155
155
  assert_equal false, @ip.include?(not_included)
156
- # test address on same prefix
156
+ # test address on same prefix
157
157
  included = @klass.new "2001:db8::8:800:200c:0/64"
158
158
  not_included = @klass.new "2001:db8:1::8:800:200c:417a/64"
159
159
  assert_equal true, @ip.include?(included)
@@ -164,11 +164,11 @@ class IPv6Test < Test::Unit::TestCase
164
164
  assert_equal true, @ip.include?(included)
165
165
  assert_equal false, @ip.include?(not_included)
166
166
  end
167
-
167
+
168
168
  def test_method_to_hex
169
169
  assert_equal @hex, @ip.to_hex
170
170
  end
171
-
171
+
172
172
  def test_method_to_s
173
173
  assert_equal "2001:db8::8:800:200c:417a", @ip.to_s
174
174
  end
@@ -178,10 +178,10 @@ class IPv6Test < Test::Unit::TestCase
178
178
  end
179
179
 
180
180
  def test_method_to_string_uncompressed
181
- str = "2001:0db8:0000:0000:0008:0800:200c:417a/64"
181
+ str = "2001:0db8:0000:0000:0008:0800:200c:417a/64"
182
182
  assert_equal str, @ip.to_string_uncompressed
183
183
  end
184
-
184
+
185
185
  def test_method_data
186
186
  if RUBY_VERSION < "2.0"
187
187
  str = " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
@@ -199,8 +199,16 @@ class IPv6Test < Test::Unit::TestCase
199
199
  def test_method_rev_domains
200
200
  assert_equal ["e.ip6.arpa", "f.ip6.arpa"], @klass.new("f000:f100::/3").rev_domains
201
201
  assert_equal ["2.a.e.f.ip6.arpa", "3.a.e.f.ip6.arpa"], @klass.new("fea3:f120::/15").rev_domains
202
- assert_equal ["2.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
203
- "3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa"],
202
+ assert_equal ["f.0.0.0.0.8.f.2.3.0.a.3.ip6.arpa"], @klass.new("3a03:2f80:f::/48").rev_domains
203
+
204
+ assert_equal ["0.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
205
+ "1.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
206
+ "2.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
207
+ "3.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
208
+ "4.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
209
+ "5.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
210
+ "6.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
211
+ "7.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa"],
204
212
  @klass.new("f000:f100::1234/125").rev_domains
205
213
  end
206
214
 
@@ -214,15 +222,15 @@ class IPv6Test < Test::Unit::TestCase
214
222
  assert_equal "1::1", @klass.new("1:0:0:0:0:0:0:1").compressed
215
223
  #assert_equal "1:1::1:2:0:0:1", @klass.new("1:1:0:1:2::1").compressed
216
224
  end
217
-
225
+
218
226
  def test_method_unspecified?
219
227
  assert_equal true, @klass.new("::").unspecified?
220
- assert_equal false, @ip.unspecified?
228
+ assert_equal false, @ip.unspecified?
221
229
  end
222
-
230
+
223
231
  def test_method_loopback?
224
232
  assert_equal true, @klass.new("::1").loopback?
225
- assert_equal false, @ip.loopback?
233
+ assert_equal false, @ip.loopback?
226
234
  end
227
235
 
228
236
  def test_method_network
@@ -244,11 +252,24 @@ class IPv6Test < Test::Unit::TestCase
244
252
  end
245
253
 
246
254
  def test_method_each_net
247
- ip = @klass.new("fd01:db8::4/3")
248
- arr = []
249
- ip.each_net {|i| arr << i.to_string}
250
- expected = ["e000::/3","f000::/3"]
251
- assert_equal expected, arr
255
+ test_addrs = []
256
+ (0..15).each do |nibble|
257
+ test_addrs << (0..7).to_a.map{(0..3).to_a.map{"%x"%nibble}.join("")}.join(":")
258
+ end
259
+ (0..128).each do |prefix|
260
+ nr_networks = 1<<((128-prefix)%4)
261
+ test_addrs.each do |adr|
262
+ net_adr = @klass.new("#{adr}/#{prefix}")
263
+ ret = net_adr.four_bit_networks
264
+ assert_equal ret.first.prefix.to_i%4, 0
265
+ assert_equal ret.size, nr_networks
266
+ assert_equal net_adr.network_u128, ret.first.network_u128
267
+ assert_equal net_adr.broadcast_u128, ret.last.broadcast_u128
268
+ # puts "#{adr}/#{prefix} #{nr_networks} #{ret}"
269
+ end
270
+ end
271
+ assert_equal ["e000::/4","f000::/4"], @klass.new("fd01:db8::4/3").four_bit_networks.map{|i| i.to_string}
272
+ assert_equal ["3a03:2f80:f::/48"], @klass.new("3a03:2f80:f::/48").four_bit_networks.map{|i| i.to_string}
252
273
  end
253
274
 
254
275
  def test_method_compare
@@ -260,7 +281,7 @@ class IPv6Test < Test::Unit::TestCase
260
281
  # ip2 should be greater than ip1
261
282
  assert_equal true, ip2 > ip1
262
283
  assert_equal false, ip1 > ip2
263
- assert_equal false, ip2 < ip1
284
+ assert_equal false, ip2 < ip1
264
285
  # ip3 should be less than ip2
265
286
  assert_equal true, ip2 > ip3
266
287
  assert_equal false, ip2 < ip3
@@ -287,7 +308,7 @@ class IPv6Test < Test::Unit::TestCase
287
308
  assert_not_equal expanded, @klass.expand("2001:0db8::cd30")
288
309
  assert_not_equal expanded, @klass.expand("2001:0db8::cd3")
289
310
  end
290
-
311
+
291
312
  def test_classmethod_compress
292
313
  compressed = "2001:db8:0:cd30::"
293
314
  expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000"
@@ -318,7 +339,7 @@ class IPv6Test < Test::Unit::TestCase
318
339
  end # class IPv6Test
319
340
 
320
341
  class IPv6UnspecifiedTest < Test::Unit::TestCase
321
-
342
+
322
343
  def setup
323
344
  @klass = IPAddress::IPv6::Unspecified
324
345
  @ip = @klass.new
@@ -347,12 +368,12 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase
347
368
  def test_method_ipv6?
348
369
  assert_equal true, @ip.ipv6?
349
370
  end
350
-
371
+
351
372
  end # class IPv6UnspecifiedTest
352
373
 
353
374
 
354
375
  class IPv6LoopbackTest < Test::Unit::TestCase
355
-
376
+
356
377
  def setup
357
378
  @klass = IPAddress::IPv6::Loopback
358
379
  @ip = @klass.new
@@ -381,11 +402,11 @@ class IPv6LoopbackTest < Test::Unit::TestCase
381
402
  def test_method_ipv6?
382
403
  assert_equal true, @ip.ipv6?
383
404
  end
384
-
405
+
385
406
  end # class IPv6LoopbackTest
386
407
 
387
408
  class IPv6MappedTest < Test::Unit::TestCase
388
-
409
+
389
410
  def setup
390
411
  @klass = IPAddress::IPv6::Mapped
391
412
  @ip = @klass.new("::172.16.10.1")
@@ -444,5 +465,5 @@ class IPv6MappedTest < Test::Unit::TestCase
444
465
  def test_mapped?
445
466
  assert_equal true, @ip.mapped?
446
467
  end
447
-
468
+
448
469
  end # class IPv6MappedTest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: construqt-ipaddress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Ceresa
@@ -40,7 +40,8 @@ files:
40
40
  - test/ipaddress_test.rb
41
41
  - test/test_helper.rb
42
42
  homepage: http://github.com/bluemonk/ipaddress
43
- licenses: []
43
+ licenses:
44
+ - Simple from Marco Ceresa
44
45
  metadata: {}
45
46
  post_install_message:
46
47
  rdoc_options: []