Newer
Older
NetAddr-IP / README
  1. NAME
  2. NetAddr::IP - Manages IPv4 addresses and subnets
  3.  
  4. SYNOPSIS
  5. use NetAddr::IP;
  6.  
  7. my $ip = new NetAddr::IP 'loopback';
  8.  
  9. print "The address is ", $ip->addr, " with mask ", $ip->mask, "\n" ;
  10.  
  11. if ($ip->within(new NetAddr::IP "127.0.0.0", "255.0.0.0")) {
  12. print "Is a loopback address\n";
  13. }
  14.  
  15. DESCRIPTION
  16. This module provides a number of methods useful for handling IPv4
  17. addresses ans subnets. Hopefully, its methods are also usable for IPv6
  18. addresses.
  19.  
  20. Methods so far include:
  21.  
  22. `->new($addr, [ $mask ])'
  23. This method creates a new IPv4 address with the supplied address in
  24. `$addr' and an optional netmask `$mask', which can be omitted to get
  25. a /32 mask.
  26.  
  27. `$addr' can be almost anything that can be resolved to an IP address
  28. in all the notations I have seen over time. It can optionally
  29. contain the mask in CIDR notation.
  30.  
  31. `->broadcast()'
  32. Returns the broadcast address for a subnet.
  33.  
  34. `->network()'
  35. Returns the "network" address for a subnet.
  36.  
  37. `->addr()'
  38. Returns the address part of the object as a dotted-quad.
  39.  
  40. `->mask()'
  41. Returns the mask as a dotted-quad.
  42.  
  43. `->masklen()'
  44. Returns the number of one bits in the mask.
  45.  
  46. `->cidr()'
  47. Returns the address and mask in CIDR notation.
  48.  
  49. `$me->contains($other)'
  50. Returns true when `$me' completely contains `$other'. False is
  51. returned otherwise and `undef' is returned if `$me' and `$other' are
  52. of different versions.
  53.  
  54. `$me->within($other)'
  55. The complement of `->contains()'. Returns true when `$me' is
  56. completely con tained within `$other'.
  57.  
  58. `->split($bits)'
  59. Returns a list of objects, representing subnets of `$bits' mask
  60. produced by splitting the original object, which is left unchanged.
  61. Note that `$bits' must be longer than the original object's mask in
  62. order for it to be splittable.
  63.  
  64. Note that `$bits' can be given as an integer (the length of the
  65. mask) or as a dotted-quad. If omitted, a host mask is assumed.
  66.  
  67. `->splitref($bits)'
  68. A (faster) version of `->split()' that returns a reference to a list
  69. of objects instead of a real list. This is useful when large numbers
  70. of objects are expected.
  71.  
  72. `->hostenum()'
  73. Returns the list of hosts within a subnet.
  74.  
  75. `->hostenumref()'
  76. Faster version of `->hostenum()', returning a reference to a list.
  77.  
  78. `$me->compact($addr1, $addr2, ...)'
  79. Given a list of objects (including `$me'), this method will compact
  80. all the addresses and subnets into the largest (ie, least specific)
  81. subnets possible that contain exactly all of the given objects.
  82.  
  83. `$me->compactref(\@list)'
  84. As usual, a faster version of =item `->compact()' that returns a
  85. reference to a list. Note that this method takes a reference to a
  86. list instead.
  87.  
  88. `->first()'
  89. Returns a new object representing the first useable IP address
  90. within the subnet (ie, the first host address).
  91.  
  92. `->last()'
  93. Returns a new object representing the last useable IP address within
  94. the subnet (ie, one less than the broadcast address).
  95.  
  96. `->num()'
  97. Returns the number of useable addresses IP addresses within the
  98. subnet, not counting the broadcast address.
  99.  
  100. EXPORT
  101.  
  102. None by default.
  103.  
  104. HISTORY
  105. 0.01
  106. * original version; Basic testing and release to CPAN as version
  107. 0.01. This is considered beta software.
  108.  
  109. 0.02
  110. * Multiple changes to fix endiannes issues. This code is now
  111. moderately tested on Wintel and Sun/Solaris boxes.
  112.  
  113. 0.03
  114. * Added ->first and ->last methods. Version changed to 0.03.
  115.  
  116. 1.00
  117. * Implemented ->new_subnet. Version changed to 1.00.
  118.  
  119. * less croak()ing when improper input is fed to the module. A more
  120. consistent 'undef' is returned now instead to allow the user to
  121. better handle the error.
  122.  
  123. 1.10
  124. * As per Marnix A. Van Ammers [mav6@ns02.comp.pge.com] suggestion,
  125. changed the syntax of the loop in host_enum to be the same of
  126. the enum method.
  127.  
  128. * Fixed the MS-DOS ^M at the end-of-line problem. This should make
  129. the module easier to use for *nix users.
  130.  
  131. 1.20
  132. * Implemented ->compact and ->expand methods.
  133.  
  134. * Applying for official name
  135.  
  136. 1.21
  137. * Added ->addr_number and ->mask_bits. Currently we return normal
  138. numbers (not BigInts). Please test this in your platform and
  139. report any problems!
  140.  
  141. 2.00
  142. * Released under the new *official* name of NetAddr::IP
  143.  
  144. 2.10
  145. * Added support for ->new($min, $max, $bits) form
  146.  
  147. * Added ->to_numeric. This helps serializing objects
  148.  
  149. 2.20
  150. * Chris Dowling reported that the sort method introduced in v1.20
  151. for ->expand and ->compact doesn't always return a number under
  152. perl versions < 5.6.0. His fix was applied and redistributed.
  153. Thanks Chris!
  154.  
  155. * This module is hopefully released with no CR-LF issues!
  156.  
  157. * Fixed a warning about uninitialized values during make test
  158.  
  159. 2.21
  160. * Dennis Boylan pointed out a bug under Linux and perhaps other
  161. platforms as well causing the error "Sort subroutine didn't
  162. return single value at
  163. /usr/lib/perl5/site_perl/5.6.0/NetAddr/IP.pm line 299, <> line
  164. 2." or similar. This was fixed.
  165.  
  166. 2.22
  167. * Some changes suggested by Jeroen Ruigrok and Anton Berezin were
  168. included. Thanks guys!
  169.  
  170. 2.23
  171. * Bug fix for /XXX.XXX.XXX.XXX netmasks under v5.6.1 suggested by
  172. Tim Wuyts. Thanks!
  173.  
  174. * Tested the module under MACHTYPE=hppa1.0-hp-hpux11.00. It is now
  175. konwn to work under Linux (Intel/AMD), Digital Unix (Alpha),
  176. Solaris (Sun), HP-UX11 (HP-PA-RISC), Windows 9x/NT/2K (using
  177. ActiveState on Intel).
  178.  
  179. 2.24
  180. * A spurious warning when expand()ing with -w under certain
  181. circumstances was removed. This involved using /31s, /32s and
  182. the same netmask as the input. Thanks to Elie Rosenblum for
  183. pointing it out.
  184.  
  185. * Slight change in license terms to ease redistribution as a
  186. Debian package.
  187.  
  188. 3.00
  189. This is a major rewrite, supposed to fix a number of issues
  190. pointed out in earlier versions.
  191.  
  192. The goals for this version include getting rid of BigInts,
  193. speeding up and also cleaning up the code, which is written in a
  194. modular enough way so as to allow IPv6 functionality in the
  195. future, taking benefit from most of the methods.
  196.  
  197. Note that no effort has been made to remain backwards compatible
  198. with earlier versions. In particular, certain semantics of the
  199. earlier versions have been removed in favor of faster
  200. performance.
  201.  
  202. This version was tested under Win98/2K (ActiveState
  203. 5.6.0/5.6.1), HP-UX11 on PA-RISC (5.6.0), RedHat Linux 6.2
  204. (5.6.0), Digital Unix on Alpha (5.6.0), Solaris on Sparc (5.6.0)
  205. and possibly others.
  206.  
  207. AUTHOR
  208. Luis E. Munoz <lem@cantv.net>
  209.  
  210. WARRANTY
  211. This software comes with the same warranty as perl itself (ie, none), so
  212. by using it you accept any and all the liability.
  213.  
  214. LICENSE
  215. This software is (c) Luis E. Munoz. It can be used under the terms of
  216. the perl artistic license provided that proper credit for the work of
  217. the author is preserved in the form of this copyright notice and license
  218. for this module.
  219.  
  220. SEE ALSO
  221. perl(1).
  222.