ipadmin 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,9 +1,9 @@
1
1
 
2
- Copyright (c) 2006 Dustin Spinhirne <dspinhir at yahoo.com>
2
+ Copyright (c) 2006 Dustin Spinhirne
3
3
  Licensed under the same terms as Ruby, No Warranty is provided.
4
4
 
5
5
 
6
- Comments are welcome. Please include 'Ruby - IPAdmin' in the title of
6
+ Comments are welcome. Please include 'IPAdmin' in the title of
7
7
  any emails.
8
8
 
9
9
  Dustin Spinhirne
@@ -50,17 +50,17 @@
50
50
  puts "cidr6 netmask in bits #{cidr6.bits()}"
51
51
  print "\n"
52
52
 
53
- # contains
53
+ # contains?
54
54
  puts "contains"
55
- puts "#{cidr4.desc} contains #{cidr4_2.desc}" if ( cidr4.contains(cidr4_2) )
56
- puts "#{cidr6.desc} contains #{cidr6_2.desc}" if ( cidr6.contains(cidr6_2) )
55
+ puts "#{cidr4.desc} contains #{cidr4_2.desc}" if ( cidr4.contains?(cidr4_2) )
56
+ puts "#{cidr6.desc} contains #{cidr6_2.desc}" if ( cidr6.contains?(cidr6_2) )
57
57
  print "\n"
58
58
 
59
59
  # desc
60
60
  puts "desc"
61
61
  puts "cidr4 description #{cidr4.desc()}"
62
62
  puts "cidr6 description #{cidr6.desc()}"
63
- puts "cidr6 short-hand description #{cidr6.desc(:Short => 1)}"
63
+ puts "cidr6 short-hand description #{cidr6.desc(:Short => true)}"
64
64
  print "\n"
65
65
 
66
66
  # enumerate
@@ -69,7 +69,7 @@
69
69
  cidr4.enumerate(:Limit => 4, :Bitstep => 32).each {|x| puts " #{x}"}
70
70
 
71
71
  puts "first 4 cidr6 addresses (bitstep 32)"
72
- cidr6.enumerate(:Limit => 4, :Bitstep => 32, :Objectify => 1).each {|x| puts " #{x.desc}"}
72
+ cidr6.enumerate(:Limit => 4, :Bitstep => 32, :Objectify => true).each {|x| puts " #{x.desc}"}
73
73
  print "\n"
74
74
 
75
75
  # hostmask_ext
@@ -80,13 +80,13 @@
80
80
  # ip
81
81
  puts "ip"
82
82
  puts "cidr4 ip #{cidr4.ip()}"
83
- puts "cidr6 short-hand ip #{cidr6.ip(:Short => 1)}"
83
+ puts "cidr6 short-hand ip #{cidr6.ip(:Short => true)}"
84
84
  print "\n"
85
85
 
86
86
  # last
87
87
  puts "last"
88
88
  puts "cidr4 last ip #{cidr4.last()}"
89
- puts "cidr6 last ip #{cidr6.last(:Short => 1)}"
89
+ puts "cidr6 last ip #{cidr6.last(:Short => true)}"
90
90
  print "\n"
91
91
 
92
92
  # netmask
@@ -103,25 +103,25 @@
103
103
  # network
104
104
  puts "network"
105
105
  puts "cidr4 network address #{cidr4.network()}"
106
- puts "cidr6 network address #{cidr6.network(:Short => 1)}"
106
+ puts "cidr6 network address #{cidr6.network(:Short => true)}"
107
107
  print "\n"
108
108
 
109
109
  # next_ip
110
110
  puts "next_ip"
111
111
  puts "cidr4 next ip #{cidr4.next_ip()}"
112
- puts "cidr6 next ip #{cidr6.next_ip(:Short => 1)}"
112
+ puts "cidr6 next ip #{cidr6.next_ip(:Short => true)}"
113
113
  print "\n"
114
114
 
115
115
  # next_subnet
116
116
  puts "next_subnet"
117
117
  puts "cidr4 next subnet #{cidr4.next_subnet()}"
118
- puts "cidr6 next subnet #{cidr6.next_subnet(:Short => 1)}"
118
+ puts "cidr6 next subnet #{cidr6.next_subnet(:Short => true)}"
119
119
  print "\n"
120
120
 
121
121
  # nth
122
122
  puts "nth"
123
123
  puts "cidr4 1st ip is #{cidr4.nth(:Index => 1)}"
124
- puts "cidr6 1st ip is #{(cidr6.nth(:Index => 1, :Objectify => 1)).base}"
124
+ puts "cidr6 1st ip is #{(cidr6.nth(:Index => 1, :Objectify => true)).base}"
125
125
  print "\n"
126
126
 
127
127
  # packed_hostmask
@@ -173,8 +173,8 @@
173
173
  puts "#{cidr4.desc} subnetted into at least 3 /28 ranges"
174
174
  cidr4.subnet(:Subnet => 28, :MinCount => 3).each {|x| puts " #{x}"}
175
175
 
176
- puts "#{cidr6.desc(:Short => 1)} subnetted into at least 4 /67 ranges"
177
- cidr6.subnet(:Subnet => 67, :MinCount => 4, :Short => 1).each {|x| puts " #{x}"}
176
+ puts "#{cidr6.desc(:Short => true)} subnetted into at least 4 /67 ranges"
177
+ cidr6.subnet(:Subnet => 67, :MinCount => 4, :Short => true).each {|x| puts " #{x}"}
178
178
 
179
179
  print "\n\n\n"
180
180
  #=====================================#
@@ -1,5 +1,5 @@
1
1
  =begin rdoc
2
- Copyright (c) 2006 Dustin Spinhirne <dspinhir at yahoo.com> -
2
+ Copyright (c) 2006 Dustin Spinhirne <http://www.spinhirne.com> -
3
3
  Licensed under the same terms as Ruby, No Warranty is provided.
4
4
  =end
5
5
 
@@ -220,9 +220,9 @@ module_function :create_net_struct
220
220
  # - Arguments:
221
221
  # * Hash with the following fields:
222
222
  # - :List -- Array of IPAdmin::CIDR or NetStruct objects
223
- # - :NetStruct -- if non-nil, return IPAdmin::NetStruct objects (optional)
224
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
225
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
223
+ # - :NetStruct -- if true, return IPAdmin::NetStruct objects (optional)
224
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
225
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
226
226
  #
227
227
  # - Returns:
228
228
  # * Array of IPAdmin::CIDR or IPAdmin::NetStruct objects
@@ -232,8 +232,8 @@ module_function :create_net_struct
232
232
  #
233
233
  def merge(options)
234
234
  version = nil
235
- short = nil
236
- objectify = nil
235
+ short = false
236
+ objectify = false
237
237
 
238
238
  # validate options
239
239
  unless ( options.kind_of?(Hash) )
@@ -245,11 +245,11 @@ def merge(options)
245
245
  end
246
246
 
247
247
  if (options[:Short])
248
- short = 1
248
+ short = true
249
249
  end
250
250
 
251
251
  if (options[:Objectify])
252
- objectify = 1
252
+ objectify = true
253
253
  end
254
254
 
255
255
  list = options[:List]
@@ -448,7 +448,7 @@ module_function :merge
448
448
  # pack_ipv4_addr()
449
449
  #==============================================================================#
450
450
 
451
- # Convert IPv4 addresses into single a byte-packed field. No attempt at
451
+ # Convert IPv4 addresses into an integer. No attempt at
452
452
  # validation is performed.
453
453
  #
454
454
  # - Arguments:
@@ -490,7 +490,7 @@ module_function :pack_ipv4_addr
490
490
  # pack_ipv4_netmask()
491
491
  #==============================================================================#
492
492
 
493
- # Convert IPv4 netmask into a single byte-packed field. Only very basic
493
+ # Convert IPv4 netmask into an integer. Only very basic
494
494
  # validation is performed.
495
495
  #
496
496
  # - Arguments:
@@ -549,7 +549,7 @@ module_function :pack_ipv4_netmask
549
549
  # pack_ipv6_addr()
550
550
  #==============================================================================#
551
551
 
552
- # Convert IPv6 addresses into a single byte-packed field. No attempt at
552
+ # Convert IPv6 addresses into an integer. No attempt at
553
553
  # validation is performed.
554
554
  #
555
555
  # - Arguments:
@@ -619,7 +619,7 @@ module_function :pack_ipv6_addr
619
619
  # pack_ipv6_netmask()
620
620
  #==============================================================================#
621
621
 
622
- # Convert IPv6 netmask into a single byte-packed field. Only very basic
622
+ # Convert IPv6 netmask into an integer. Only very basic
623
623
  # validation is performed.
624
624
  #
625
625
  # - Arguments:
@@ -676,7 +676,8 @@ module_function :pack_ipv6_netmask
676
676
  # - :Bitstep -- enumerate in X sized steps (optional)
677
677
  # - :Boundaries -- array of (2) IPAdmin::CIDR objects
678
678
  # - :Limit -- limit returned list to X number of items (optional)
679
- # - :Objectify -- return IPAdmin::CIDR objects (optional)
679
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
680
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
680
681
  #
681
682
  # - Returns:
682
683
  # * Array of IP addresses or IPAdmin::CIDR objects
@@ -691,7 +692,9 @@ module_function :pack_ipv6_netmask
691
692
  def range(options)
692
693
  list = []
693
694
  bitstep = 1
694
- objectify,limit = nil,nil
695
+ objectify = false
696
+ short = false
697
+ limit = nil
695
698
 
696
699
  # check options
697
700
  if (options)
@@ -711,7 +714,11 @@ def range(options)
711
714
  end
712
715
 
713
716
  if( options.has_key?(:Objectify) )
714
- objectify = 1
717
+ objectify = true
718
+ end
719
+
720
+ if( options.has_key?(:Short) )
721
+ short = true
715
722
  end
716
723
 
717
724
  if( options.has_key?(:Limit) )
@@ -758,7 +765,10 @@ def range(options)
758
765
 
759
766
  until (my_ip == boundaries[1])
760
767
  if (!objectify)
761
- list.push( IPAdmin.unpack_ipv6_addr(my_ip) )
768
+ my_ips = IPAdmin.unpack_ipv6_addr(my_ip)
769
+ my_ips = IPAdmin.shorten(my_ips) if (short)
770
+ list.push(my_ips)
771
+
762
772
  else
763
773
  my_ip_s = IPAdmin.unpack_ipv6_addr(my_ip)
764
774
  list.push( IPAdmin::CIDR.new(:CIDR => my_ip_s) )
@@ -808,45 +818,58 @@ def shorten(addr)
808
818
 
809
819
  # make sure this isnt already shorthand
810
820
  if (addr =~ /::/)
811
- raise "#{addr} already appears to be in IPv6 shorthand notation."
821
+ return(addr)
812
822
  end
813
823
 
814
- # look for most 0 fields
815
- found_zero = nil
816
- pattern = ""
817
- zero_fields = []
818
- fields = addr.split(":")
819
-
824
+ # look for most consecutive '0' fields
825
+ start_field,end_field = nil,nil
826
+ start_end = []
827
+ consecutive,longest = 0,0
828
+ fields = addr.split(":")
829
+
820
830
  (0..(fields.length-1)).each do |x|
821
831
  fields[x] = fields[x].to_i(16)
822
832
 
823
833
  if (fields[x] == 0)
824
- if (!found_zero)
825
- found_zero = 1
834
+ if (!start_field)
835
+ start_field = x
836
+ end_field = x
837
+ else
838
+ end_field = x
826
839
  end
827
- pattern << ":0"
840
+ consecutive += 1
828
841
  else
829
- if (found_zero)
830
- found_zero = nil
831
- pattern << ":"
832
- zero_fields.push(pattern)
833
- pattern = ""
842
+ if (start_field)
843
+ if (consecutive > longest)
844
+ longest = consecutive
845
+ start_end = [start_field,end_field]
846
+ start_field,end_field = nil,nil
847
+ end
848
+ consecutive = 0
834
849
  end
835
850
  end
836
851
 
837
852
  fields[x] = fields[x].to_s(16)
838
853
  end
839
-
840
- # pattern should be the longest set of 0's in a row
841
- zero_fields.push(pattern) if (pattern != "")
842
- pattern = ""
843
- zero_fields.each do |x|
844
- pattern = x if (x.length > pattern.length)
854
+
855
+ # if our longest set of 0's is at the end, then start & end fields
856
+ # are already set. if not, then make start & end fields the ones we've
857
+ # stored away in start_end
858
+ if (consecutive > longest)
859
+ longest = consecutive
860
+ else
861
+ start_field = start_end[0]
862
+ end_field = start_end[1]
845
863
  end
846
864
 
847
- short = fields.join(":")
848
- short.sub!(pattern,"::")
849
-
865
+ if (longest > 1)
866
+ fields[start_field] = ''
867
+ start_field += 1
868
+ fields.slice!(start_field..end_field)
869
+ end
870
+ short = fields.join(':')
871
+ short << ':' if (short =~ /:$/)
872
+
850
873
  return(short)
851
874
  end
852
875
  module_function :shorten
@@ -941,8 +964,8 @@ module_function :sort
941
964
  # unpack_ipv4_addr()
942
965
  #==============================================================================#
943
966
 
944
- # Unack IPv4 address back into a printable string. No attempt at validation
945
- # is performed.
967
+ # Unack a packed IPv4 address back into a printable string. No attempt at
968
+ # validation is performed.
946
969
  #
947
970
  # - Arguments:
948
971
  # * Byte-packed IPv4 address
@@ -977,7 +1000,7 @@ module_function :unpack_ipv4_addr
977
1000
  # unpack_ipv4_netmask()
978
1001
  #==============================================================================#
979
1002
 
980
- # Unack IPv4 netmask into a integer representing the number of
1003
+ # Unack a packed IPv4 netmask into a integer representing the number of
981
1004
  # bits in the CIDR mask. No attempt at validation is performed.
982
1005
  #
983
1006
  # - Arguments:
@@ -1012,8 +1035,8 @@ module_function :unpack_ipv4_netmask
1012
1035
  # unpack_ipv6_addr()
1013
1036
  #==============================================================================#
1014
1037
 
1015
- # Unack IPv6 address back into a printable string. No attempt at validation
1016
- # is performed.
1038
+ # Unack a packed IPv6 address back into a printable string. No attempt at
1039
+ # validation is performed.
1017
1040
  #
1018
1041
  # - Arguments:
1019
1042
  # * Byte-packed IPv6 address
@@ -1053,7 +1076,7 @@ module_function :unpack_ipv6_addr
1053
1076
  # unpack_ipv6_netmask()
1054
1077
  #==============================================================================#
1055
1078
 
1056
- # Unack IPv6 netmask into a integer representing the number of
1079
+ # Unack a packed IPv6 netmask into a integer representing the number of
1057
1080
  # bits in the CIDR mask. No attempt at validation is performed.
1058
1081
  #
1059
1082
  # - Arguments:
@@ -1130,7 +1153,7 @@ module_function :unshorten
1130
1153
  # * IPv4 address
1131
1154
  #
1132
1155
  # - Returns:
1133
- # * byte-packed IP on valid, or exception on error.
1156
+ # * packed IP on valid, or exception on error.
1134
1157
  #
1135
1158
  # Example:
1136
1159
  # IPAdmin.validate_ipv4_addr('192.168.1.1')
@@ -1189,7 +1212,7 @@ module_function :validate_ipv4_addr
1189
1212
  # * IPv4 netmask in cidr or extended notation
1190
1213
  #
1191
1214
  # - Returns:
1192
- # * byte-packed netmask on valid, or exception on error.
1215
+ # * packed netmask on valid, or exception on error.
1193
1216
  #
1194
1217
  # Example:
1195
1218
  # IPAdmin.validate_ipv4_netmask('255.255.255.0')
@@ -1276,7 +1299,7 @@ module_function :validate_ipv4_netmask
1276
1299
  # * IPv6 address
1277
1300
  #
1278
1301
  # - Returns:
1279
- # * byte-packed IP on valid, or exception on error.
1302
+ # * packed IP on valid, or exception on error.
1280
1303
  #
1281
1304
  # Example:
1282
1305
  # IPAdmin.validate_ipv6_addr('fec0::')
@@ -1352,7 +1375,7 @@ module_function :validate_ipv6_addr
1352
1375
  # * IPv6 netmask in cidr notation
1353
1376
  #
1354
1377
  # - Returns:
1355
- # * byte-packed netmask on valid, or exception on error.
1378
+ # * packed netmask on valid, or exception on error.
1356
1379
  #
1357
1380
  # Example:
1358
1381
  # IPAdmin.validate_ipv6_netmask('64')
@@ -1602,7 +1625,7 @@ class CIDR
1602
1625
 
1603
1626
 
1604
1627
  #==============================================================================#
1605
- # contains()
1628
+ # contains?()
1606
1629
  #==============================================================================#
1607
1630
 
1608
1631
  # Determines if this object contains (is supernet of)
@@ -1612,14 +1635,14 @@ class CIDR
1612
1635
  # * IPAdmin:CIDR object
1613
1636
  #
1614
1637
  # - Returns:
1615
- # * 1 on true, nil on false
1638
+ # * true or false
1616
1639
  #
1617
1640
  # Example:
1618
1641
  # cidr4_2 = IPAdmin::CIDR.new(:CIDR => '192.168.1.0/26')
1619
- # contains = cidr4.contains(cidr4_2) --> 1
1642
+ # contains? = cidr4.contains(cidr4_2) --> true
1620
1643
  #
1621
- def contains(object)
1622
- is_contained = nil
1644
+ def contains?(object)
1645
+ is_contained = false
1623
1646
 
1624
1647
  if (object.kind_of?(IPAdmin::CIDR))
1625
1648
  network = object.packed_network
@@ -1640,11 +1663,11 @@ class CIDR
1640
1663
  # else we can tell by or'ing network and @network by @hostmask
1641
1664
  # and comparing the results
1642
1665
  if (network == @network)
1643
- is_contained = 1 if (netmask > @netmask)
1666
+ is_contained = true if (netmask > @netmask)
1644
1667
 
1645
1668
  else
1646
1669
  if ( (network | @hostmask) == (@network | @hostmask) )
1647
- is_contained = 1
1670
+ is_contained = true
1648
1671
  end
1649
1672
  end
1650
1673
 
@@ -1664,8 +1687,8 @@ class CIDR
1664
1687
  #
1665
1688
  # - Arguments:
1666
1689
  # * Optional hash with the following fields:
1667
- # - :IP -- if non-nil, return the ip/netmask passed during initialization (optional)
1668
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
1690
+ # - :IP -- true, return the ip/netmask passed during initialization (optional)
1691
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
1669
1692
  #
1670
1693
  # - Returns:
1671
1694
  # * Description in network/netmask format
@@ -1675,8 +1698,8 @@ class CIDR
1675
1698
  # puts cidr4.desc(:IP => 1) --> 192.168.1.1/24
1676
1699
  #
1677
1700
  def desc(options=nil)
1678
- short = nil
1679
- orig_ip = nil
1701
+ short = false
1702
+ orig_ip = false
1680
1703
 
1681
1704
  if (options)
1682
1705
  unless (options.kind_of? Hash)
@@ -1684,11 +1707,11 @@ class CIDR
1684
1707
  end
1685
1708
 
1686
1709
  if (options.has_key?(:Short))
1687
- short = 1
1710
+ short = true
1688
1711
  end
1689
1712
 
1690
1713
  if (options.has_key?(:IP))
1691
- orig_ip = 1
1714
+ orig_ip = true
1692
1715
  end
1693
1716
  end
1694
1717
 
@@ -1729,8 +1752,8 @@ class CIDR
1729
1752
  # * Optional Hash with the following fields:
1730
1753
  # - :Bitstep -- enumerate in X sized steps (optional)
1731
1754
  # - :Limit -- limit returned list to X number of items (optional)
1732
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
1733
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
1755
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
1756
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
1734
1757
  #
1735
1758
  # - Returns:
1736
1759
  # * Array of IP addresses or IPAdmin::CIDR objects
@@ -1740,9 +1763,9 @@ class CIDR
1740
1763
  #
1741
1764
  def enumerate(options=nil)
1742
1765
  bitstep = 1
1743
- objectify = nil
1766
+ objectify = false
1744
1767
  limit = nil
1745
- short = nil
1768
+ short = false
1746
1769
 
1747
1770
  if (options)
1748
1771
  if( options.has_key?(:Bitstep) )
@@ -1750,7 +1773,7 @@ class CIDR
1750
1773
  end
1751
1774
 
1752
1775
  if( options.has_key?(:Objectify) )
1753
- objectify = 1
1776
+ objectify = true
1754
1777
  end
1755
1778
 
1756
1779
  if( options.has_key?(:Limit) )
@@ -1758,7 +1781,7 @@ class CIDR
1758
1781
  end
1759
1782
 
1760
1783
  if( options.has_key?(:Short) )
1761
- short = 1
1784
+ short = true
1762
1785
  end
1763
1786
  end
1764
1787
 
@@ -1854,8 +1877,8 @@ class CIDR
1854
1877
  #
1855
1878
  # - Arguments:
1856
1879
  # * Optional Hash with the following fields:
1857
- # - :Objectify -- if non-nil, return IPAdmin::CIDR object (optional)
1858
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
1880
+ # - :Objectify -- if true, return IPAdmin::CIDR object (optional)
1881
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
1859
1882
  #
1860
1883
  # - Returns:
1861
1884
  # * IP address or IPAdmin::CIDR object.
@@ -1864,8 +1887,8 @@ class CIDR
1864
1887
  # puts cidr4.ip() --> 192.168.1.1
1865
1888
  #
1866
1889
  def ip(options=nil)
1867
- objectify = nil
1868
- short =nil
1890
+ objectify = false
1891
+ short = false
1869
1892
 
1870
1893
  if (options)
1871
1894
  unless(options.kind_of?(Hash))
@@ -1874,11 +1897,11 @@ class CIDR
1874
1897
  end
1875
1898
 
1876
1899
  if( options.has_key?(:Short) )
1877
- short = 1
1900
+ short = true
1878
1901
  end
1879
1902
 
1880
1903
  if( options.has_key?(:Objectify) )
1881
- objectify = 1
1904
+ objectify = true
1882
1905
  end
1883
1906
  end
1884
1907
 
@@ -1911,8 +1934,8 @@ class CIDR
1911
1934
  #
1912
1935
  # - Arguments:
1913
1936
  # * Optional Hash with the following fields:
1914
- # - :Objectify -- if non-nil, return IPAdmin::CIDR object (optional)
1915
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
1937
+ # - :Objectify -- if true, return IPAdmin::CIDR object (optional)
1938
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
1916
1939
  #
1917
1940
  # - Returns:
1918
1941
  # * IP address or IPAdmin::CIDR object.
@@ -1921,8 +1944,8 @@ class CIDR
1921
1944
  # puts cidr4.last() --> 192.168.1.255
1922
1945
  #
1923
1946
  def last(options=nil)
1924
- objectify = nil
1925
- short = nil
1947
+ objectify = false
1948
+ short = false
1926
1949
 
1927
1950
  if (options)
1928
1951
  unless(options.kind_of?(Hash))
@@ -1931,11 +1954,11 @@ class CIDR
1931
1954
  end
1932
1955
 
1933
1956
  if( options.has_key?(:Short) )
1934
- short = 1
1957
+ short = true
1935
1958
  end
1936
1959
 
1937
1960
  if( options.has_key?(:Objectify) )
1938
- objectify = 1
1961
+ objectify = true
1939
1962
  end
1940
1963
 
1941
1964
  end
@@ -2031,8 +2054,8 @@ class CIDR
2031
2054
  #
2032
2055
  # - Arguments:
2033
2056
  # * Optional Hash with the following fields:
2034
- # - :Objectify -- if non-nil, return IPAdmin::CIDR object (optional)
2035
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2057
+ # - :Objectify -- if true, return IPAdmin::CIDR object (optional)
2058
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2036
2059
  #
2037
2060
  # - Returns:
2038
2061
  # * IP address or IPAdmin::CIDR object.
@@ -2041,8 +2064,8 @@ class CIDR
2041
2064
  # puts cidr4.network() --> 192.168.1.0
2042
2065
  #
2043
2066
  def network(options=nil)
2044
- objectify = nil
2045
- short =nil
2067
+ objectify = false
2068
+ short = false
2046
2069
 
2047
2070
  if (options)
2048
2071
  unless(options.kind_of?(Hash))
@@ -2051,11 +2074,11 @@ class CIDR
2051
2074
  end
2052
2075
 
2053
2076
  if( options.has_key?(:Short) )
2054
- short = 1
2077
+ short = true
2055
2078
  end
2056
2079
 
2057
2080
  if( options.has_key?(:Objectify) )
2058
- objectify = 1
2081
+ objectify = true
2059
2082
  end
2060
2083
  end
2061
2084
 
@@ -2091,8 +2114,8 @@ class CIDR
2091
2114
  # - Arguments:
2092
2115
  # * Optional Hash with the following fields:
2093
2116
  # - :Bitstep -- step in X sized steps (optional)
2094
- # - :Objectify -- if non-nil, return IPAdmin::CIDR object (optional)
2095
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2117
+ # - :Objectify -- if true, return IPAdmin::CIDR object (optional)
2118
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2096
2119
  #
2097
2120
  # - Returns:
2098
2121
  # * IP address or IPAdmin::CIDR object.
@@ -2102,8 +2125,8 @@ class CIDR
2102
2125
  #
2103
2126
  def next_ip(options=nil)
2104
2127
  bitstep = 1
2105
- objectify = nil
2106
- short = nil
2128
+ objectify = false
2129
+ short = false
2107
2130
 
2108
2131
  if (options)
2109
2132
  unless(options.kind_of?(Hash))
@@ -2116,11 +2139,11 @@ class CIDR
2116
2139
  end
2117
2140
 
2118
2141
  if( options.has_key?(:Short) )
2119
- short = 1
2142
+ short = true
2120
2143
  end
2121
2144
 
2122
2145
  if( options.has_key?(:Objectify) )
2123
- objectify = 1
2146
+ objectify = true
2124
2147
  end
2125
2148
  end
2126
2149
 
@@ -2159,8 +2182,8 @@ class CIDR
2159
2182
  # - Arguments:
2160
2183
  # * Optional Hash with the following fields:
2161
2184
  # - :Bitstep -- step in X sized steps. (optional)
2162
- # - :Objectify -- if non-nil, return IPAdmin::CIDR object (optional)
2163
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2185
+ # - :Objectify -- if true, return IPAdmin::CIDR object (optional)
2186
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2164
2187
  #
2165
2188
  # - Returns:
2166
2189
  # * CIDR address or IPAdmin::CIDR object.
@@ -2170,8 +2193,8 @@ class CIDR
2170
2193
  #
2171
2194
  def next_subnet(options=nil)
2172
2195
  bitstep = 1
2173
- objectify = nil
2174
- short = nil
2196
+ objectify = false
2197
+ short = false
2175
2198
 
2176
2199
  if (options)
2177
2200
  unless(options.kind_of?(Hash))
@@ -2184,11 +2207,11 @@ class CIDR
2184
2207
  end
2185
2208
 
2186
2209
  if( options.has_key?(:Short) )
2187
- short = 1
2210
+ short = true
2188
2211
  end
2189
2212
 
2190
2213
  if( options.has_key?(:Objectify) )
2191
- objectify = 1
2214
+ objectify = true
2192
2215
  end
2193
2216
  end
2194
2217
 
@@ -2228,8 +2251,8 @@ class CIDR
2228
2251
  # - Arguments:
2229
2252
  # * Hash with the following fields:
2230
2253
  # - :Index -- index number of the IP address to return
2231
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
2232
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2254
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
2255
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2233
2256
  #
2234
2257
  # - Returns:
2235
2258
  # * IP address or IPAdmin::CIDR object.
@@ -2238,8 +2261,8 @@ class CIDR
2238
2261
  # puts cidr4.nth(:Index => 1) --> 192.168.1.1
2239
2262
  #
2240
2263
  def nth(options)
2241
- objectify = nil
2242
- short = nil
2264
+ objectify = false
2265
+ short = false
2243
2266
 
2244
2267
  unless(options.kind_of?(Hash))
2245
2268
  raise Argumenterror, "Expected Hash, but " +
@@ -2252,11 +2275,11 @@ class CIDR
2252
2275
  index = options[:Index]
2253
2276
 
2254
2277
  if( options.has_key?(:Short) )
2255
- short = 1
2278
+ short = true
2256
2279
  end
2257
2280
 
2258
2281
  if( options.has_key?(:Objectify) )
2259
- objectify = 1
2282
+ objectify = true
2260
2283
  end
2261
2284
 
2262
2285
  my_ip = @network + index
@@ -2292,7 +2315,7 @@ class CIDR
2292
2315
  # packed_hostmask()
2293
2316
  #==============================================================================#
2294
2317
 
2295
- # Provide byte-packed Hostmask of this object.
2318
+ # Provide an integer representing the packed Hostmask of this object.
2296
2319
  #
2297
2320
  # - Arguments:
2298
2321
  # * none
@@ -2316,7 +2339,7 @@ class CIDR
2316
2339
  # packed_ip()
2317
2340
  #==============================================================================#
2318
2341
 
2319
- # Provide byte-packed IP of this object.
2342
+ # Provide an integer representing the packed IP of this object.
2320
2343
  #
2321
2344
  # - Arguments:
2322
2345
  # * none
@@ -2340,7 +2363,7 @@ class CIDR
2340
2363
  # packed_netmask()
2341
2364
  #==============================================================================#
2342
2365
 
2343
- # Provide byte-packed Netmask of this object.
2366
+ # Provide an integer representing the packed Netmask of this object.
2344
2367
  #
2345
2368
  # - Arguments:
2346
2369
  # * none
@@ -2364,7 +2387,7 @@ class CIDR
2364
2387
  # packed_network()
2365
2388
  #==============================================================================#
2366
2389
 
2367
- # Provide byte-packed Network address of this object.
2390
+ # Provide an integer representing the packed Network address of this object.
2368
2391
  #
2369
2392
  # - Arguments:
2370
2393
  # * none
@@ -2395,8 +2418,8 @@ class CIDR
2395
2418
  # * Hash with the following fields:
2396
2419
  # - :Bitstep -- enumerate in X sized steps (optional)
2397
2420
  # - :Indexes -- array of (2) index numbers of the addresses to use as boundaries
2398
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
2399
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2421
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
2422
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2400
2423
  #
2401
2424
  # - Returns:
2402
2425
  # * Array of IP addresses or IPAdmin::CIDR objects
@@ -2405,8 +2428,8 @@ class CIDR
2405
2428
  # list = cidr4.range(:Indexes => [0,1]) --> ['192.168.1.0','192.168.1.1']
2406
2429
  #
2407
2430
  def range(options)
2408
- objectify = nil
2409
- short = nil
2431
+ objectify = false
2432
+ short = false
2410
2433
  bitstep = 1
2411
2434
 
2412
2435
  unless(options.kind_of?(Hash))
@@ -2432,11 +2455,11 @@ class CIDR
2432
2455
  end
2433
2456
 
2434
2457
  if( options.has_key?(:Short) )
2435
- short = 1
2458
+ short = true
2436
2459
  end
2437
2460
 
2438
2461
  if( options.has_key?(:Objectify) )
2439
- objectify = 1
2462
+ objectify = true
2440
2463
  end
2441
2464
 
2442
2465
  if( options.has_key?(:Bitstep) )
@@ -2475,14 +2498,14 @@ class CIDR
2475
2498
  # remainder()
2476
2499
  #==============================================================================#
2477
2500
 
2478
- # Given a subnet of the current CIDR, provide the remainder of
2479
- # the current CIDR.
2501
+ # Given a subnet of the current CIDR, provide the remaining subnets of
2502
+ # the CIDR.
2480
2503
  #
2481
2504
  # - Arguments:
2482
2505
  # * Optional hash with the following fields:
2483
2506
  # - :Exclude -- IPAdmin::CIDR object to use in calculating the remainder.
2484
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
2485
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2507
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
2508
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2486
2509
  #
2487
2510
  # - Returns:
2488
2511
  # * Array of CIDR addresses or IPAdmin::CIDR objects
@@ -2511,23 +2534,23 @@ class CIDR
2511
2534
  end
2512
2535
 
2513
2536
  if( options.has_key?(:Short) )
2514
- short = 1
2537
+ short = true
2515
2538
  end
2516
2539
 
2517
2540
  if( options.has_key?(:Objectify) )
2518
- objectify = 1
2541
+ objectify = true
2519
2542
  end
2520
2543
 
2521
2544
  # make sure 'to_exclude' is the same ip version
2522
2545
  unless ( to_exclude.version == @version )
2523
- raise "#{to_exclude.desc(:Short => 1)} is of a different " +
2524
- "IP version than #{self.desc(:Short => 1)}."
2546
+ raise "#{to_exclude.desc(:Short => true)} is of a different " +
2547
+ "IP version than #{self.desc(:Short => true)}."
2525
2548
  end
2526
2549
 
2527
2550
  # make sure we contain 'to_exclude'
2528
- unless ( self.contains(to_exclude) == 1 )
2529
- raise "#{to_exclude.desc(:Short => 1)} does not fit " +
2530
- "within the bounds of #{self.desc(:Short => 1)}."
2551
+ unless ( self.contains?(to_exclude) == true )
2552
+ raise "#{to_exclude.desc(:Short => true)} does not fit " +
2553
+ "within the bounds of #{self.desc(:Short => true)}."
2531
2554
  end
2532
2555
 
2533
2556
  # split this cidr in half & see which half 'to_exclude'
@@ -2712,8 +2735,8 @@ class CIDR
2712
2735
  # * Optional hash with the following fields:
2713
2736
  # - :IPCount -- Minimum number of IP's that new subnets should contain (optional)
2714
2737
  # - :MinCount -- Minimum number of X sized subnets to return (optional)
2715
- # - :Objectify -- if non-nil, return IPAdmin::CIDR objects (optional)
2716
- # - :Short -- if non-nil, return IPv6 addresses in short-hand notation (optional)
2738
+ # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
2739
+ # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
2717
2740
  # - :Subnet -- Netmask (in bits) of new subnets (optional)
2718
2741
  #
2719
2742
  # - Returns:
@@ -2732,8 +2755,8 @@ class CIDR
2732
2755
  my_mask = self.bits
2733
2756
  subnet_bits = my_mask + 1
2734
2757
  min_count = nil
2735
- objectify = nil
2736
- short = nil
2758
+ objectify = false
2759
+ short = false
2737
2760
 
2738
2761
  if (options)
2739
2762
  unless (options.kind_of? Hash)
@@ -2758,11 +2781,11 @@ class CIDR
2758
2781
  end
2759
2782
 
2760
2783
  if( options.has_key?(:Short) )
2761
- short = 1
2784
+ short = true
2762
2785
  end
2763
2786
 
2764
2787
  if( options.has_key?(:Objectify) )
2765
- objectify = 1
2788
+ objectify = true
2766
2789
  end
2767
2790
 
2768
2791
  end
@@ -3126,7 +3149,7 @@ class Tree
3126
3149
  # * Two NetStruct objects
3127
3150
  #
3128
3151
  # - Returns:
3129
- # * 1 if struct1 contains or is equal to struct2, or nil if not.
3152
+ # * true if struct1 contains or is equal to struct2, or false if not.
3130
3153
  #
3131
3154
  # Example:
3132
3155
  # is_contained = contains(struct1,struct2)
@@ -3149,14 +3172,14 @@ class Tree
3149
3172
  # if network1 == network2, then we have to go by netmask length
3150
3173
  # else we can tell by or'ing network1 and network2 by hostmask1
3151
3174
  # and comparing the results
3152
- is_contained = nil
3175
+ is_contained = false
3153
3176
  if (network1 == network2)
3154
3177
  if (netmask2 >= netmask1)
3155
- is_contained = 1
3178
+ is_contained = true
3156
3179
  end
3157
3180
  else
3158
3181
  if ( (network1 | hostmask1) == (network2 | hostmask1) )
3159
- is_contained = 1
3182
+ is_contained = true
3160
3183
  end
3161
3184
  end
3162
3185
 
@@ -3250,7 +3273,7 @@ class Tree
3250
3273
  # * IPAdmin::CIDR object
3251
3274
  #
3252
3275
  # - Returns:
3253
- # * 1 if exists, nil if not
3276
+ # * true or false
3254
3277
  #
3255
3278
  # Example:
3256
3279
  # added = tree.exists?(cidr)
@@ -3272,10 +3295,11 @@ class Tree
3272
3295
  home_struct,home_branch = find_home(net_struct, @root)
3273
3296
 
3274
3297
  # check for match
3298
+ found = false
3275
3299
  if (home_struct)
3276
3300
  if ( (net_struct.network == home_struct.network) &&
3277
3301
  (net_struct.netmask == home_struct.netmask) )
3278
- found = 1
3302
+ found = true
3279
3303
  end
3280
3304
  end
3281
3305
 
@@ -3389,12 +3413,12 @@ class Tree
3389
3413
  # - :Limit -- Maximum entries to return (optional)
3390
3414
  # - :Subnet -- Netmask (in bits) of space to find(optional)
3391
3415
  #
3392
- # Note:
3393
- # :Subnet always takes precedence over :IPCount.
3394
- #
3395
3416
  # - Returns:
3396
3417
  # * ordered array of IPAdmin::CIDR objects
3397
3418
  #
3419
+ # Note:
3420
+ # :Subnet always takes precedence over :IPCount.
3421
+ #
3398
3422
  # Example:
3399
3423
  # list = tree.find_space(:Subnet => 27)
3400
3424
  # list = tree.find_space(:IPCount => 33, :Limit => 2)
@@ -3482,7 +3506,7 @@ class Tree
3482
3506
  # * IPAdmin::CIDR object
3483
3507
  #
3484
3508
  # - Returns:
3485
- # * 1 on success, or nil
3509
+ # * true on success, or false
3486
3510
  #
3487
3511
  # Example:
3488
3512
  # did_prune = tree.prune(ip)
@@ -3506,9 +3530,10 @@ class Tree
3506
3530
  end
3507
3531
 
3508
3532
  # remove if home_struct.object = object
3533
+ pruned = false
3509
3534
  if (home_struct.object = object)
3510
3535
  home_branch.delete(home_struct)
3511
- pruned = 1
3536
+ pruned = true
3512
3537
  end
3513
3538
 
3514
3539
  return(pruned)
@@ -3529,7 +3554,7 @@ class Tree
3529
3554
  # * IPAdmin::CIDR object
3530
3555
  #
3531
3556
  # - Returns:
3532
- # * 1 on success, or nil
3557
+ # * true on success, or false
3533
3558
  #
3534
3559
  # Example:
3535
3560
  # did_remove = tree.remove(ip)
@@ -3549,6 +3574,7 @@ class Tree
3549
3574
  home_struct,home_branch = find_home(net_struct, @root)
3550
3575
 
3551
3576
  # remove if home_struct.object = object
3577
+ removed = false
3552
3578
  if (home_struct.object = object)
3553
3579
 
3554
3580
  # if we have children subnets, move them up one level
@@ -3566,7 +3592,7 @@ class Tree
3566
3592
  end
3567
3593
 
3568
3594
  home_branch.delete(home_struct)
3569
- removed = 1
3595
+ removed = true
3570
3596
  end
3571
3597
 
3572
3598
  return(removed)
@@ -16,7 +16,7 @@ class TestCIDR < Test::Unit::TestCase
16
16
  assert_not_nil(IPAdmin::CIDR.new(:CIDR => 'fec0::1/64') )
17
17
  end
18
18
 
19
- def test_contains
19
+ def test_contains?
20
20
 
21
21
  cidr4 = IPAdmin::CIDR.new(:CIDR => '192.168.1.0/24')
22
22
  cidr4_2 = IPAdmin::CIDR.new(:CIDR => '192.168.1.0/26')
@@ -25,10 +25,10 @@ class TestCIDR < Test::Unit::TestCase
25
25
  cidr6_2 = IPAdmin::CIDR.new(:CIDR => 'fec0::/96')
26
26
  cidr6_3 = IPAdmin::CIDR.new(:CIDR => 'fe80::/96')
27
27
 
28
- assert_equal(1,cidr4.contains(cidr4_2) )
29
- assert_equal(1,cidr6.contains(cidr6_2) )
30
- assert_nil(cidr4.contains(cidr4_3) )
31
- assert_nil(cidr6.contains(cidr6_3) )
28
+ assert_equal(true,cidr4.contains?(cidr4_2) )
29
+ assert_equal(true,cidr6.contains?(cidr6_2) )
30
+ assert_equal(false,cidr4.contains?(cidr4_3) )
31
+ assert_equal(false,cidr6.contains?(cidr6_3) )
32
32
  end
33
33
 
34
34
  def test_nth
@@ -36,12 +36,12 @@ class TestCIDR < Test::Unit::TestCase
36
36
  cidr6 = IPAdmin::CIDR.new(:CIDR => 'fec0::/126')
37
37
 
38
38
  assert_equal('192.168.1.1',cidr4.nth(:Index => 1) )
39
- assert_kind_of(IPAdmin::CIDR,cidr4.nth(:Index => 1, :Objectify => 1) )
39
+ assert_kind_of(IPAdmin::CIDR,cidr4.nth(:Index => 1, :Objectify => true) )
40
40
  assert_raise(RuntimeError){ cidr4.nth(:Index => 256) }
41
41
  assert_raise(ArgumentError){ cidr4.nth() }
42
42
 
43
43
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0001',cidr6.nth(:Index => 1) )
44
- assert_equal('fec0::1',cidr6.nth(:Index => 1, :Short => 1) )
44
+ assert_equal('fec0::1',cidr6.nth(:Index => 1, :Short => true) )
45
45
  assert_raise(RuntimeError){ cidr6.nth(:Index => 10) }
46
46
  end
47
47
 
@@ -51,7 +51,7 @@ class TestCIDR < Test::Unit::TestCase
51
51
 
52
52
  assert_equal(['192.168.1.0'],cidr4.enumerate(:Limit => 1) )
53
53
  assert_equal(['fec0:0000:0000:0000:0000:0000:0000:0000'],cidr6.enumerate(:Limit => 1) )
54
- assert_equal(['fec0::'],cidr6.enumerate(:Limit => 1, :Short => 1) )
54
+ assert_equal(['fec0::'],cidr6.enumerate(:Limit => 1, :Short => true) )
55
55
 
56
56
 
57
57
  enums4 = cidr4.enumerate(:Limit => 2, :Bitstep => 5)
@@ -59,7 +59,7 @@ class TestCIDR < Test::Unit::TestCase
59
59
  assert_equal('192.168.1.5', enums4[1] )
60
60
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0005', enums6[1] )
61
61
 
62
- enums4 = cidr4.enumerate(:Objectify => 1,:Limit => 1)
62
+ enums4 = cidr4.enumerate(:Objectify => true,:Limit => 1)
63
63
  assert_kind_of(IPAdmin::CIDR, enums4[0] )
64
64
 
65
65
  end
@@ -73,7 +73,7 @@ class TestCIDR < Test::Unit::TestCase
73
73
  assert_equal('192.168.2.0',next4 )
74
74
  assert_equal('fec0:0000:0000:0001:0000:0000:0000:0000',next6 )
75
75
 
76
- next6 = cidr6.next_ip(:Short => 1)
76
+ next6 = cidr6.next_ip(:Short => true)
77
77
  assert_equal('fec0:0:0:1::',next6 )
78
78
 
79
79
  next4 = cidr4.next_ip(:Bitstep => 2)
@@ -81,8 +81,8 @@ class TestCIDR < Test::Unit::TestCase
81
81
  assert_equal('192.168.2.1',next4 )
82
82
  assert_equal('fec0:0000:0000:0001:0000:0000:0000:0001',next6 )
83
83
 
84
- next4 = cidr4.next_ip(:Objectify => 1)
85
- next6 = cidr6.next_ip(:Objectify => 1)
84
+ next4 = cidr4.next_ip(:Objectify => true)
85
+ next6 = cidr6.next_ip(:Objectify => true)
86
86
  assert_equal('192.168.2.0/32',next4.desc )
87
87
  assert_equal('fec0:0000:0000:0001:0000:0000:0000:0000/128',next6.desc )
88
88
 
@@ -97,7 +97,7 @@ class TestCIDR < Test::Unit::TestCase
97
97
  assert_equal('192.168.2.0/24',next4 )
98
98
  assert_equal('fec0:0000:0000:0001:0000:0000:0000:0000/64',next6 )
99
99
 
100
- next6 = cidr6.next_subnet(:Short => 1)
100
+ next6 = cidr6.next_subnet(:Short => true)
101
101
  assert_equal('fec0:0:0:1::/64',next6 )
102
102
 
103
103
  next4 = cidr4.next_subnet(:Bitstep => 2)
@@ -105,8 +105,8 @@ class TestCIDR < Test::Unit::TestCase
105
105
  assert_equal('192.168.3.0/24',next4 )
106
106
  assert_equal('fec0:0000:0000:0002:0000:0000:0000:0000/64',next6 )
107
107
 
108
- next4 = cidr4.next_subnet(:Objectify => 1)
109
- next6 = cidr6.next_subnet(:Objectify => 1)
108
+ next4 = cidr4.next_subnet(:Objectify => true)
109
+ next6 = cidr6.next_subnet(:Objectify => true)
110
110
  assert_equal('192.168.2.0/24',next4.desc )
111
111
  assert_equal('fec0:0000:0000:0001:0000:0000:0000:0000/64',next6.desc )
112
112
 
@@ -117,7 +117,7 @@ class TestCIDR < Test::Unit::TestCase
117
117
  cidr6 = IPAdmin::CIDR.new(:CIDR => 'fec0::/64')
118
118
 
119
119
  range4 = cidr4.range(:Indexes => [25,0], :Bitstep => 5)
120
- range6 = cidr6.range(:Indexes => [25,0], :Bitstep => 5, :Short => 1)
120
+ range6 = cidr6.range(:Indexes => [25,0], :Bitstep => 5, :Short => true)
121
121
 
122
122
  assert_equal(6,range4.length)
123
123
  assert_equal(6,range6.length)
@@ -135,7 +135,7 @@ class TestCIDR < Test::Unit::TestCase
135
135
  assert_equal(2,remainder.length)
136
136
  assert_equal('192.168.1.0/26',remainder[0])
137
137
 
138
- remainder = cidr4.remainder(:Exclude => cidr4_2, :Objectify => 1)
138
+ remainder = cidr4.remainder(:Exclude => cidr4_2, :Objectify => true)
139
139
  assert_equal('192.168.1.128/25',remainder[1].desc)
140
140
  end
141
141
 
@@ -146,7 +146,7 @@ class TestCIDR < Test::Unit::TestCase
146
146
  new4 = cidr4.resize(:Subnet => 23)
147
147
  new6 = cidr6.resize(:Subnet => 63)
148
148
  assert_equal('192.168.0.0/23',new4.desc )
149
- assert_equal('fec0::/63',new6.desc(:Short => 1) )
149
+ assert_equal('fec0::/63',new6.desc(:Short => true) )
150
150
 
151
151
  cidr4.resize!(:Subnet => 25)
152
152
  cidr6.resize!(:Subnet => 67)
@@ -164,7 +164,7 @@ class TestCIDR < Test::Unit::TestCase
164
164
  assert_equal('192.168.1.0/24',cidr4.desc() )
165
165
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0000/64',cidr6.desc() )
166
166
 
167
- assert_equal('fec0::/64',cidr6.desc(:Short => 1) )
167
+ assert_equal('fec0::/64',cidr6.desc(:Short => true) )
168
168
 
169
169
  assert_equal('0.0.0.255',cidr4.hostmask_ext() )
170
170
 
@@ -173,11 +173,11 @@ class TestCIDR < Test::Unit::TestCase
173
173
 
174
174
  assert_equal('192.168.1.1',cidr4.ip() )
175
175
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0001',cidr6.ip() )
176
- assert_equal('fec0::1',cidr6.ip(:Short => 1) )
176
+ assert_equal('fec0::1',cidr6.ip(:Short => true) )
177
177
 
178
178
  assert_equal('192.168.1.255',cidr4.last() )
179
179
  assert_equal('fec0:0000:0000:0000:ffff:ffff:ffff:ffff',cidr6.last() )
180
- assert_equal('fec0::ffff:ffff:ffff:ffff',cidr6.last(:Short => 1) )
180
+ assert_equal('fec0::ffff:ffff:ffff:ffff',cidr6.last(:Short => true) )
181
181
 
182
182
  assert_equal('/24',cidr4.netmask() )
183
183
  assert_equal('/64',cidr6.netmask() )
@@ -186,7 +186,7 @@ class TestCIDR < Test::Unit::TestCase
186
186
 
187
187
  assert_equal('192.168.1.0',cidr4.network() )
188
188
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0000',cidr6.network() )
189
- assert_equal('fec0::',cidr6.network(:Short => 1) )
189
+ assert_equal('fec0::',cidr6.network(:Short => true) )
190
190
 
191
191
  assert_equal(256,cidr4.size() )
192
192
  assert_equal(2**64,cidr6.size() )
@@ -206,7 +206,7 @@ class TestCIDR < Test::Unit::TestCase
206
206
  assert_equal('192.168.1.64/26', subnet4[1])
207
207
  assert_equal('192.168.1.128/25', subnet4[2])
208
208
 
209
- subnet4 = cidr4.subnet(:Subnet => 28, :MinCount => 3, :Objectify => 1)
209
+ subnet4 = cidr4.subnet(:Subnet => 28, :MinCount => 3, :Objectify => true)
210
210
  assert_equal('192.168.1.0/28', subnet4[0].desc)
211
211
  assert_equal('192.168.1.16/28', subnet4[1].desc)
212
212
  assert_equal('192.168.1.32/28', subnet4[2].desc)
@@ -5,7 +5,7 @@ require 'test/unit'
5
5
 
6
6
 
7
7
 
8
- class TestFunct < Test::Unit::TestCase
8
+ class TestMethods < Test::Unit::TestCase
9
9
 
10
10
  def test_pack_ipv4_addr
11
11
  assert_equal(2**32-1, IPAdmin.pack_ipv4_addr('255.255.255.255') )
@@ -184,7 +184,12 @@ class TestFunct < Test::Unit::TestCase
184
184
  assert_equal('fec0::', IPAdmin.shorten('fec0:0000:0000:0000:0000:0000:0000:0000') )
185
185
  assert_equal('fec0::2:0:0:1', IPAdmin.shorten('fec0:0000:0000:0000:0002:0000:0000:0001') )
186
186
  assert_equal('fec0::2:0:0:1', IPAdmin.shorten('fec0:00:0000:0:02:0000:0:1') )
187
- assert_raise(RuntimeError){ IPAdmin.shorten('fec0::') }
187
+ assert_equal('fec0::2:2:0:0:1', IPAdmin.shorten('fec0:0000:0000:0002:0002:0000:0000:0001') )
188
+ assert_equal('fec0:0:0:1::', IPAdmin.shorten('fec0:0000:0000:0001:0000:0000:0000:0000') )
189
+ assert_equal('fec0:1:1:1:1:1:1:1', IPAdmin.shorten('fec0:0001:0001:0001:0001:0001:0001:0001') )
190
+ assert_equal('fec0:ffff:ffff:0:ffff:ffff:ffff:ffff', IPAdmin.shorten('fec0:ffff:ffff:0000:ffff:ffff:ffff:ffff') )
191
+ assert_equal('fec0:ffff:ffff:ffff:ffff:ffff:ffff:ffff', IPAdmin.shorten('fec0:ffff:ffff:ffff:ffff:ffff:ffff:ffff') )
192
+ assert_equal('fec0::', IPAdmin.shorten('fec0::') )
188
193
  end
189
194
 
190
195
  def test_unshorten
@@ -246,7 +251,7 @@ class TestFunct < Test::Unit::TestCase
246
251
  IPAdmin::CIDR.new(:CIDR => 'fec0::2/127')]
247
252
 
248
253
  merge4 = IPAdmin.merge(:List => cidr4)
249
- merge4_2 = IPAdmin.merge(:List => cidr4_2, :Objectify => 1)
254
+ merge4_2 = IPAdmin.merge(:List => cidr4_2, :Objectify => true)
250
255
  merge6 = IPAdmin.merge(:List => cidr6)
251
256
 
252
257
  assert_equal(5, merge4.length)
@@ -182,9 +182,9 @@ class TestTree < Test::Unit::TestCase
182
182
  tree6.add(cidr6_1)
183
183
  tree6.add(cidr6_2)
184
184
 
185
- assert_equal(1, tree4.exists?(cidr4_1))
186
- assert_equal(1, tree6.exists?(cidr6_2))
187
- assert_nil(tree4.exists?(cidr4_3))
185
+ assert_equal(true, tree4.exists?(cidr4_1))
186
+ assert_equal(true, tree6.exists?(cidr6_2))
187
+ assert_equal(false, tree4.exists?(cidr4_3))
188
188
 
189
189
  end
190
190
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ipadmin
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-02-21 00:00:00 -06:00
6
+ version: 0.2.1
7
+ date: 2006-03-08 00:00:00 -06:00
8
8
  summary: A package for manipulating IPv4/IPv6 address space.
9
9
  require_paths:
10
10
  - lib
@@ -32,9 +32,9 @@ files:
32
32
  - lib/ip_admin.rb
33
33
  - README
34
34
  test_files:
35
- - tests/functions_test.rb
36
- - tests/cidr_test.rb
35
+ - tests/methods_test.rb
37
36
  - tests/tree_test.rb
37
+ - tests/cidr_test.rb
38
38
  rdoc_options: []
39
39
  extra_rdoc_files:
40
40
  - README