netaddr 1.4.0 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of netaddr might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd69b081c04694ed2db113b810b07e19ba7f8c9ebe446bca31af3b9f73955777
4
+ data.tar.gz: 4510ea5730575cbc8f606de4edd21ef054ba661fb9b1b2aacbdfa6f872055ad5
5
+ SHA512:
6
+ metadata.gz: 12f90e81555cb39d0b51cd10c108b185da1cc4fb48d684858b60e5ada9d3584bb74ec54904335e962a9f14bd194e5c27cee4ab0d017a00ee0a03c223a79d3894
7
+ data.tar.gz: 78efa87669e4f37defda27d375e57d2dde8cd356b9a9ceac19e0ade7ce080733ee48e766ca100d11c411e7cb87e0d2230c711a24a1db90d73292fff3b69cea18
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # netaddr
2
+ I originally created this package back in 2007 out of the need for a tool
3
+ which I could use to track an inventory of constantly changing IP subnets.
4
+ At the time, I was in the process of migrating away from Perl and towards Ruby
5
+ as my primary scripting language. I have since migrated away from using Ruby so
6
+ I have not made any major modifications to this code base since 2008 (aside from a
7
+ handful of bug fixes that others have pointed out).
8
+
9
+ Dustin Spinhirne
data/changelog CHANGED
@@ -1,8 +1,27 @@
1
+ Version 1.5.2
2
+ Changes:
3
+ * bug fixes from: https://github.com/KirillSmirnov, https://github.com/rwhitworth, https://github.com/y13i
1
4
 
2
- ==Version
3
- ====1.3.0
5
+ Version 1.5.1
6
+ Changes:
7
+ * fixed bug with NetAddr#merge (credit to Daniel Boughton)
4
8
 
5
- ===New Features
9
+
10
+ Version 1.5.0
11
+ Changes:
12
+ * fixed bug with EUI48#to_eui64 (credit to Erik Kline)
13
+ * fixed bug with u/l bit toggle on EUI#link_local (credit to Erik Kline)
14
+ * added EUI#to_ipv6
15
+ * added NetAddr#supernets
16
+
17
+
18
+ Version 1.4.0
19
+ Changes:
20
+ * Added additional options to NetAddr#sort
21
+
22
+
23
+ Version 1.3.0
24
+ New Features:
6
25
  * added CIDR#[]
7
26
  * added CIDR#succ (CIDR objects may now be used as args for the standard Ruby Range class)
8
27
  * added CIDR#allocate_rfc3531
@@ -12,14 +31,12 @@
12
31
  * added EUI#to_i
13
32
  * added EUI#to_s
14
33
 
15
- ===Changes
34
+ Changes:
16
35
  * deprecated 'packed' methods
17
36
 
18
37
 
19
- ==Version
20
- ====1.2.0
21
-
22
- ===Changes
38
+ Version 1.2.0
39
+ Changes:
23
40
  * CIDRv4#new and CIDRv6#new methods have been changed for the sake of speed improvements.
24
41
  Please use the CIDR#create method instead.
25
42
  * changes to CIDR#wildcard_mask
@@ -28,7 +45,7 @@
28
45
  * bug fix and *vast* simplification of NetAddr.merge
29
46
 
30
47
 
31
- ===New Features
48
+ New Features:
32
49
  * speed improvements
33
50
  * added CIDR#set_wildcard_mask
34
51
  * added <=>, >, <, == methods to CIDR
data/lib/cidr.rb CHANGED
@@ -1,9 +1,3 @@
1
- =begin rdoc
2
- Copyleft (c) 2006 Dustin Spinhirne
3
-
4
- Licensed under the same terms as Ruby, No Warranty is provided.
5
- =end
6
-
7
1
  module NetAddr
8
2
 
9
3
  #=CIDR - Classless Inter-Domain Routing
@@ -41,9 +35,6 @@ class CIDR
41
35
 
42
36
  private_class_method :new
43
37
 
44
- #==============================================================================#
45
- # attr_reader/attr_writer
46
- #==============================================================================#
47
38
 
48
39
  # IP version 4 or 6.
49
40
  attr_reader :version
@@ -70,10 +61,6 @@ private_class_method :new
70
61
  @tag = new_tag
71
62
  end
72
63
 
73
- #==============================================================================#
74
- # create()
75
- #==============================================================================#
76
-
77
64
  #===Synopsis
78
65
  #Create a new CIDRv4 or CIDRv6 object.
79
66
  #CIDR formatted netmasks take precedence over extended formatted ones.
@@ -81,21 +68,15 @@ private_class_method :new
81
68
  #:Mask takes precedence over netmask given within CIDR addresses.
82
69
  #Version will be auto-detected if not specified.
83
70
  #
84
- # NetAddr::CIDR.create('192.168.1.1/24')
85
- # NetAddr::CIDR.create('192.168.1.1 255.255.255.0')
86
- # NetAddr::CIDR.create(0x0a010001,
87
- # :Mask => 0xffffff00
88
- # :Version => 4)
89
- # NetAddr::CIDR.create('192.168.1.1',
90
- # :WildcardMask => ['0.7.0.255', true])
91
- # NetAddr::CIDR.create('192.168.1.1',
92
- # :WildcardMask => [0x000007ff, true]
93
- # NetAddr::CIDR.create('192.168.5.0',
94
- # :WildcardMask => ['255.248.255.0'])
95
- # NetAddr::CIDR.create('fec0::/64')
96
- # NetAddr::CIDR.create('fec0::/64',
97
- # :Tag => {'interface' => 'g0/1'})
98
- # NetAddr::CIDR.create('::ffff:192.168.1.1/96')
71
+ # NetAddr::CIDR.create('192.168.1.1/24')
72
+ # NetAddr::CIDR.create('192.168.1.1 255.255.255.0')
73
+ # NetAddr::CIDR.create(0x0a010001,:Mask => 0xffffff00:Version => 4)
74
+ # NetAddr::CIDR.create('192.168.1.1',:WildcardMask => ['0.7.0.255', true])
75
+ # NetAddr::CIDR.create('192.168.1.1',:WildcardMask => [0x000007ff, true]
76
+ # NetAddr::CIDR.create('192.168.5.0',:WildcardMask => ['255.248.255.0'])
77
+ # NetAddr::CIDR.create('fec0::/64')
78
+ # NetAddr::CIDR.create('fec0::/64',:Tag => {'interface' => 'g0/1'})
79
+ # NetAddr::CIDR.create('::ffff:192.168.1.1/96')
99
80
  #
100
81
  #===Arguments:
101
82
  #* addr = CIDR address as a String, or an IP address as an Integer
@@ -221,10 +202,6 @@ private_class_method :new
221
202
  return( NetAddr.cidr_build(version, ip, netmask, tag, wildcard_mask, wildcard_mask_bit_flipped) )
222
203
  end
223
204
 
224
- #==============================================================================#
225
- # initialize()
226
- #==============================================================================#
227
-
228
205
  # This method performs absolutely no error checking, and is meant to be used only by
229
206
  # other internal methods for the sake of the speedier creation of CIDR objects.
230
207
  # Please consider using #create unless you know what you are doing with 100% certainty.
@@ -267,10 +244,6 @@ private_class_method :new
267
244
 
268
245
  end
269
246
 
270
- #==============================================================================#
271
- # <()
272
- #==============================================================================#
273
-
274
247
  #===Synopsis
275
248
  #Compare the sort order of the current CIDR with a provided CIDR and return true
276
249
  #if current CIDR is less than provided CIDR.
@@ -307,10 +280,6 @@ private_class_method :new
307
280
  return(lt)
308
281
  end
309
282
 
310
- #==============================================================================#
311
- # <=>()
312
- #==============================================================================#
313
-
314
283
  #===Synopsis
315
284
  #Compare the sort order of the current CIDR with a provided CIDR and return:
316
285
  #* 1 if the current CIDR is greater than the provided CIDR
@@ -350,10 +319,6 @@ private_class_method :new
350
319
  return(comparasin)
351
320
  end
352
321
 
353
- #==============================================================================#
354
- # ==()
355
- #==============================================================================#
356
-
357
322
  #===Synopsis
358
323
  #Compare the sort order of the current CIDR with a provided CIDR and return true
359
324
  #if current CIDR is equal to the provided CIDR.
@@ -391,10 +356,6 @@ private_class_method :new
391
356
  end
392
357
  alias :eql? :==
393
358
 
394
- #==============================================================================#
395
- # >()
396
- #==============================================================================#
397
-
398
359
  #===Synopsis
399
360
  #Compare the sort order of the current CIDR with a provided CIDR and return true
400
361
  #if current CIDR is greater than provided CIDR.
@@ -431,10 +392,6 @@ private_class_method :new
431
392
  return(gt)
432
393
  end
433
394
 
434
- #==============================================================================#
435
- # []
436
- #==============================================================================#
437
-
438
395
  #===Synopsis
439
396
  #Provide the IP at the given index of the CIDR.
440
397
  #
@@ -463,10 +420,6 @@ private_class_method :new
463
420
  return(addr)
464
421
  end
465
422
 
466
- #==============================================================================#
467
- # allocate_rfc3531()
468
- #==============================================================================#
469
-
470
423
  #===Synopsis
471
424
  #RFC 3531 describes a flexible method for IP subnet allocation from
472
425
  #a larger parent network. Given the new netmask for subnet allocations from this CIDR,
@@ -564,10 +517,6 @@ private_class_method :new
564
517
  return(cidr_list)
565
518
  end
566
519
 
567
- #==============================================================================#
568
- # arpa()
569
- #==============================================================================#
570
-
571
520
  #===Synopsis
572
521
  #Depending on the IP version of the current CIDR,
573
522
  #return either an in-addr.arpa. or ip6.arpa. string. The netmask will be used
@@ -624,10 +573,6 @@ private_class_method :new
624
573
  return(arpa)
625
574
  end
626
575
 
627
- #==============================================================================#
628
- # bits()
629
- #==============================================================================#
630
-
631
576
  #===Synopsis
632
577
  #Provide number of bits in Netmask.
633
578
  # Example:
@@ -644,10 +589,6 @@ private_class_method :new
644
589
  return(NetAddr.mask_to_bits(@netmask))
645
590
  end
646
591
 
647
- #==============================================================================#
648
- # cmp()
649
- #==============================================================================#
650
-
651
592
  #===Synopsis
652
593
  #Compare the current CIDR with a provided CIDR and return:
653
594
  #* 1 if the current CIDR contains (is supernet of) the provided CIDR
@@ -689,10 +630,6 @@ private_class_method :new
689
630
  return(comparasin)
690
631
  end
691
632
 
692
- #==============================================================================#
693
- # contains?()
694
- #==============================================================================#
695
-
696
633
  #===Synopsis
697
634
  #Determines if this CIDR contains (is supernet of)
698
635
  #the provided CIDR address or NetAddr::CIDR object.
@@ -732,63 +669,13 @@ end
732
669
  return(contains)
733
670
  end
734
671
 
735
- #==============================================================================#
736
- # desc()
737
- #==============================================================================#
738
-
739
672
  #===Synopsis
740
- #Returns network/netmask in CIDR format.
741
- #
742
- # Example:
743
- # cidr4 = NetAddr::CIDR.create('192.168.1.1/24')
744
- # cidr6 = NetAddr::CIDR.create('fec0::/64')
745
- # cidr4.desc(:IP => true) => "192.168.1.1/24"
746
- # cidr4.desc() => "192.168.1.0/24"
747
- # cidr6.desc(:Short => true) => "fec0::/64"
748
- #
749
- #===Arguments:
750
- #* options = Optional hash with the following keys:
751
- # :IP -- if true, return the original ip/netmask passed during initialization
752
- # :Short -- if true, return IPv6 addresses in short-hand notation
753
- #
754
- #===Returns:
755
- #* String
673
+ #See to_s
756
674
  #
757
675
  def desc(options=nil)
758
- known_args = [:IP, :Short]
759
- short = false
760
- orig_ip = false
761
-
762
- if (options)
763
- if (!options.kind_of? Hash)
764
- raise ArgumentError, "Expected Hash, but #{options.class} provided."
765
- end
766
- NetAddr.validate_args(options.keys,known_args)
767
-
768
- if (options.has_key?(:Short) && options[:Short] == true)
769
- short = true
770
- end
771
-
772
- if (options.has_key?(:IP) && options[:IP] == true)
773
- orig_ip = true
774
- end
775
- end
776
-
777
- if (!orig_ip)
778
- ip = NetAddr.ip_int_to_str(@network, @version)
779
- else
780
- ip = NetAddr.ip_int_to_str(@ip, @version)
781
- end
782
- ip = NetAddr.shorten(ip) if (short && @version == 6)
783
- mask = NetAddr.mask_to_bits(@netmask)
784
-
785
- return("#{ip}/#{mask}")
676
+ to_s(options)
786
677
  end
787
678
 
788
- #==============================================================================#
789
- # enumerate()
790
- #==============================================================================#
791
-
792
679
  #===Synopsis
793
680
  #Provide all IP addresses contained within the IP space of this CIDR.
794
681
  #
@@ -853,7 +740,7 @@ end
853
740
  my_ip = my_ip + bitstep
854
741
  change_mask = @hostmask | my_ip
855
742
  if (limit)
856
- limit = limit -1
743
+ limit = limit - 1
857
744
  break if (limit == 0)
858
745
  end
859
746
  end
@@ -861,10 +748,6 @@ end
861
748
  return(list)
862
749
  end
863
750
 
864
- #==============================================================================#
865
- # fill_in()
866
- #==============================================================================#
867
-
868
751
  #===Synopsis
869
752
  #Given a list of subnets of the current CIDR, return a new list with any
870
753
  #holes (missing subnets) filled in.
@@ -940,10 +823,6 @@ end
940
823
  end
941
824
  end
942
825
 
943
- #==============================================================================#
944
- # ip()
945
- #==============================================================================#
946
-
947
826
  #===Synopsis
948
827
  #Provide original IP address passed during initialization.
949
828
  #
@@ -966,7 +845,7 @@ end
966
845
 
967
846
  if (options)
968
847
  if (!options.kind_of?(Hash))
969
- raise Argumenterror, "Expected Hash, but " +
848
+ raise ArgumentError, "Expected Hash, but " +
970
849
  "#{options.class} provided."
971
850
  end
972
851
  NetAddr.validate_args(options.keys,known_args)
@@ -991,10 +870,6 @@ end
991
870
  return(ip)
992
871
  end
993
872
 
994
- #==============================================================================#
995
- # is_contained?()
996
- #==============================================================================#
997
-
998
873
  #===Synopsis
999
874
  #Determines if this CIDR is contained within (is subnet of)
1000
875
  #the provided CIDR address or NetAddr::CIDR object.
@@ -1035,10 +910,6 @@ end
1035
910
  return(is_contained)
1036
911
  end
1037
912
 
1038
- #==============================================================================#
1039
- # last()
1040
- #==============================================================================#
1041
-
1042
913
  #===Synopsis
1043
914
  #Provide last IP address in this CIDR object.
1044
915
  #
@@ -1061,7 +932,7 @@ end
1061
932
 
1062
933
  if (options)
1063
934
  if (!options.kind_of?(Hash))
1064
- raise Argumenterror, "Expected Hash, but " +
935
+ raise ArgumentError, "Expected Hash, but " +
1065
936
  "#{options.class} provided."
1066
937
  end
1067
938
  NetAddr.validate_args(options.keys,known_args)
@@ -1087,10 +958,6 @@ end
1087
958
  return(ip)
1088
959
  end
1089
960
 
1090
- #==============================================================================#
1091
- # matches?()
1092
- #==============================================================================#
1093
-
1094
961
  #===Synopsis
1095
962
  #Given an IP address (or if a NetAddr::CIDR object, then the original IP of that object), determine
1096
963
  #if it falls within the range of addresses resulting from the combination of the
@@ -1126,10 +993,6 @@ end
1126
993
  return(false)
1127
994
  end
1128
995
 
1129
- #==============================================================================#
1130
- # multicast_mac()
1131
- #==============================================================================#
1132
-
1133
996
  #===Synopsis
1134
997
  #Assuming this CIDR is a valid multicast address (224.0.0.0/4 for IPv4
1135
998
  #and ff00::/8 for IPv6), return its ethernet MAC address (EUI-48) mapping.
@@ -1185,10 +1048,6 @@ end
1185
1048
  return(eui)
1186
1049
  end
1187
1050
 
1188
- #==============================================================================#
1189
- # netmask()
1190
- #==============================================================================#
1191
-
1192
1051
  #===Synopsis
1193
1052
  #Provide netmask in CIDR format (/yy).
1194
1053
  #
@@ -1207,10 +1066,6 @@ end
1207
1066
  return("/#{bits}")
1208
1067
  end
1209
1068
 
1210
- #==============================================================================#
1211
- # network()
1212
- #==============================================================================#
1213
-
1214
1069
  #===Synopsis
1215
1070
  #Provide base network address.
1216
1071
  #
@@ -1233,7 +1088,7 @@ end
1233
1088
 
1234
1089
  if (options)
1235
1090
  if (!options.kind_of?(Hash))
1236
- raise Argumenterror, "Expected Hash, but " +
1091
+ raise ArgumentError, "Expected Hash, but " +
1237
1092
  "#{options.class} provided."
1238
1093
  end
1239
1094
  NetAddr.validate_args(options.keys,known_args)
@@ -1261,10 +1116,6 @@ end
1261
1116
  alias :base :network
1262
1117
  alias :first :network
1263
1118
 
1264
- #==============================================================================#
1265
- # next_ip()
1266
- #==============================================================================#
1267
-
1268
1119
  #===Synopsis
1269
1120
  #Provide the next IP following the last available IP within this CIDR object.
1270
1121
  #
@@ -1291,7 +1142,7 @@ end
1291
1142
 
1292
1143
  if (options)
1293
1144
  if (!options.kind_of?(Hash))
1294
- raise Argumenterror, "Expected Hash, but " +
1145
+ raise ArgumentError, "Expected Hash, but " +
1295
1146
  "#{options.class} provided."
1296
1147
  end
1297
1148
  NetAddr.validate_args(options.keys,known_args)
@@ -1326,10 +1177,6 @@ end
1326
1177
  return(next_ip)
1327
1178
  end
1328
1179
 
1329
- #==============================================================================#
1330
- # next_subnet()
1331
- #==============================================================================#
1332
-
1333
1180
  #===Synopsis
1334
1181
  #Provide the next subnet following this CIDR object. The next subnet will
1335
1182
  #be of the same size as the current CIDR object.
@@ -1357,7 +1204,7 @@ end
1357
1204
 
1358
1205
  if (options)
1359
1206
  if (!options.kind_of?(Hash))
1360
- raise Argumenterror, "Expected Hash, but " +
1207
+ raise ArgumentError, "Expected Hash, but " +
1361
1208
  "#{options.class} provided."
1362
1209
  end
1363
1210
  NetAddr.validate_args(options.keys,known_args)
@@ -1393,10 +1240,6 @@ end
1393
1240
  return(next_sub)
1394
1241
  end
1395
1242
 
1396
- #==============================================================================#
1397
- # nth()
1398
- #==============================================================================#
1399
-
1400
1243
  #===Synopsis
1401
1244
  #Provide the nth IP within this object.
1402
1245
  #
@@ -1455,10 +1298,6 @@ end
1455
1298
  return(my_ip)
1456
1299
  end
1457
1300
 
1458
- #==============================================================================#
1459
- # range()
1460
- #==============================================================================#
1461
-
1462
1301
  #===Synopsis
1463
1302
  #Given a set of index numbers for this CIDR, return all IP addresses within the
1464
1303
  #CIDR that are between them (inclusive). If an upper bound is not provided, then
@@ -1552,10 +1391,6 @@ end
1552
1391
  return(list)
1553
1392
  end
1554
1393
 
1555
- #==============================================================================#
1556
- # remainder()
1557
- #==============================================================================#
1558
-
1559
1394
  #===Synopsis
1560
1395
  #Given a single subnet of the current CIDR, provide the remainder of
1561
1396
  #the subnets. For example if the original CIDR is 192.168.0.0/24 and you
@@ -1650,10 +1485,6 @@ end
1650
1485
  return(new_subnets)
1651
1486
  end
1652
1487
 
1653
- #==============================================================================#
1654
- # resize()
1655
- #==============================================================================#
1656
-
1657
1488
  #===Synopsis
1658
1489
  #Resize the CIDR by changing the size of the Netmask.
1659
1490
  #Return the resulting CIDR as a new object.
@@ -1669,7 +1500,7 @@ end
1669
1500
  #* NetAddr::CIDR object
1670
1501
  #
1671
1502
  def resize(bits)
1672
- raise Argumenterror, "Integer or Hash expected, but " +
1503
+ raise ArgumentError, "Integer or Hash expected, but " +
1673
1504
  "#{bits.class} provided." if (!bits.kind_of?(Integer))
1674
1505
 
1675
1506
  NetAddr.validate_ip_netmask(bits, :Version => @version)
@@ -1679,10 +1510,6 @@ end
1679
1510
  return( NetAddr.cidr_build(@version, network, netmask) )
1680
1511
  end
1681
1512
 
1682
- #==============================================================================#
1683
- # resize!()
1684
- #==============================================================================#
1685
-
1686
1513
  #===Synopsis
1687
1514
  #Resize the current CIDR by changing the size of the Netmask. The original IP
1688
1515
  #passed during initialization will be set to the base network address if
@@ -1699,7 +1526,7 @@ end
1699
1526
  #* True
1700
1527
  #
1701
1528
  def resize!(bits)
1702
- raise Argumenterror, "Integer or Hash expected, but " +
1529
+ raise ArgumentError, "Integer or Hash expected, but " +
1703
1530
  "#{bits.class} provided." if (!bits.kind_of?(Integer))
1704
1531
 
1705
1532
  NetAddr.validate_ip_netmask(bits, :Version => @version)
@@ -1717,10 +1544,6 @@ end
1717
1544
  return(true)
1718
1545
  end
1719
1546
 
1720
- #==============================================================================#
1721
- # set_wildcard_mask()
1722
- #==============================================================================#
1723
-
1724
1547
  #===Synopsis
1725
1548
  #Set the wildcard mask. Wildcard masks are typically used for matching
1726
1549
  #entries in an access-list.
@@ -1756,10 +1579,6 @@ end
1756
1579
  return(nil)
1757
1580
  end
1758
1581
 
1759
- #==============================================================================#
1760
- # size()
1761
- #==============================================================================#
1762
-
1763
1582
  #===Synopsis
1764
1583
  #Provide number of IP addresses within this CIDR.
1765
1584
  #
@@ -1777,10 +1596,6 @@ end
1777
1596
  return(@hostmask + 1)
1778
1597
  end
1779
1598
 
1780
- #==============================================================================#
1781
- # subnet()
1782
- #==============================================================================#
1783
-
1784
1599
  #===Synopsis
1785
1600
  #Create subnets for this CIDR. There are 2 ways to create subnets:
1786
1601
  # * By providing the netmask (in bits) of the new subnets with :Bits.
@@ -1928,10 +1743,6 @@ end
1928
1743
  return(new_subnets)
1929
1744
  end
1930
1745
 
1931
- #==============================================================================#
1932
- # succ()
1933
- #==============================================================================#
1934
-
1935
1746
  #===Synopsis
1936
1747
  #Provide the next subnet following this CIDR object. The next subnet will
1937
1748
  #be of the same size as the current CIDR object.
@@ -1959,10 +1770,6 @@ end
1959
1770
  return(next_sub)
1960
1771
  end
1961
1772
 
1962
- #==============================================================================#
1963
- # to_i()
1964
- #==============================================================================#
1965
-
1966
1773
  #===Synopsis
1967
1774
  #Convert the requested attribute of the CIDR to an Integer.
1968
1775
  # Example:
@@ -1995,9 +1802,54 @@ end
1995
1802
  end
1996
1803
  end
1997
1804
 
1998
- #==============================================================================#
1999
- # wildcard_mask()
2000
- #==============================================================================#
1805
+ #===Synopsis
1806
+ #Returns network/netmask in CIDR format.
1807
+ #
1808
+ # Example:
1809
+ # cidr4 = NetAddr::CIDR.create('192.168.1.1/24')
1810
+ # cidr6 = NetAddr::CIDR.create('fec0::/64')
1811
+ # cidr4.desc(:IP => true) => "192.168.1.1/24"
1812
+ # cidr4.to_s => "192.168.1.0/24"
1813
+ # cidr6.to_s(:Short => true) => "fec0::/64"
1814
+ #
1815
+ #===Arguments:
1816
+ #* options = Optional hash with the following keys:
1817
+ # :IP -- if true, return the original ip/netmask passed during initialization
1818
+ # :Short -- if true, return IPv6 addresses in short-hand notation
1819
+ #
1820
+ #===Returns:
1821
+ #* String
1822
+ #
1823
+ def to_s(options=nil)
1824
+ known_args = [:IP, :Short]
1825
+ short = false
1826
+ orig_ip = false
1827
+
1828
+ if (options)
1829
+ if (!options.kind_of? Hash)
1830
+ raise ArgumentError, "Expected Hash, but #{options.class} provided."
1831
+ end
1832
+ NetAddr.validate_args(options.keys,known_args)
1833
+
1834
+ if (options.has_key?(:Short) && options[:Short] == true)
1835
+ short = true
1836
+ end
1837
+
1838
+ if (options.has_key?(:IP) && options[:IP] == true)
1839
+ orig_ip = true
1840
+ end
1841
+ end
1842
+
1843
+ if (!orig_ip)
1844
+ ip = NetAddr.ip_int_to_str(@network, @version)
1845
+ else
1846
+ ip = NetAddr.ip_int_to_str(@ip, @version)
1847
+ end
1848
+ ip = NetAddr.shorten(ip) if (short && @version == 6)
1849
+ mask = NetAddr.mask_to_bits(@netmask)
1850
+
1851
+ return("#{ip}/#{mask}")
1852
+ end
2001
1853
 
2002
1854
  #===Synopsis
2003
1855
  #Return the wildcard mask.
@@ -2036,17 +1888,9 @@ class CIDRv4 < CIDR
2036
1888
 
2037
1889
  public_class_method :new
2038
1890
 
2039
- #==============================================================================#
2040
- # broadcast()
2041
- #==============================================================================#
2042
-
2043
1891
  # Alias for last
2044
1892
  alias :broadcast :last
2045
1893
 
2046
- #==============================================================================#
2047
- # hostmask_ext()
2048
- #==============================================================================#
2049
-
2050
1894
  #===Synopsis
2051
1895
  #Provide IPv4 Hostmask in extended format (y.y.y.y).
2052
1896
  #
@@ -2064,10 +1908,6 @@ class CIDRv4 < CIDR
2064
1908
  return(NetAddr.ip_int_to_str(@hostmask, @version))
2065
1909
  end
2066
1910
 
2067
- #==============================================================================#
2068
- # netmask_ext()
2069
- #==============================================================================#
2070
-
2071
1911
  #===Synopsis
2072
1912
  #Provide IPv4 netmask in extended format (y.y.y.y).
2073
1913
  #
@@ -2099,10 +1939,6 @@ end # end class CIDRv4
2099
1939
  class CIDRv6 < CIDR
2100
1940
  public_class_method :new
2101
1941
 
2102
- #==============================================================================#
2103
- # unique_local()
2104
- #==============================================================================#
2105
-
2106
1942
  #===Synopsis
2107
1943
  #Generate an IPv6 Unique Local CIDR address based on the algorithm described
2108
1944
  #in RFC 4193.