On Mon, 12 Nov 2012, Matthew Musgrove wrote:
Can you explain what functionality wasn't available in NetAddr::IP that
you needed? (I use that at work for IP and subnet handling.)
Can you talk a little bit about the rough edges you needed to smooth over?
There were a few things we needed. First, we need to represent single IP
addresses and not as /32 (or /128) subnets, but as the addresses
themselves.
The other things we added were a ->max_netmask method, which figures out
the biggest subnet that a given subnet could be a part of, for example
1.1.1.4/32 has a max netmask of 28.
We also fixed the incredibly insane behavior of ->first, ->last, and
->nth. The special cases make it a huge mess. Our methods always
return all addresses, including broadcast & network, regardless of the
subnet size.
We also tweaked ->as_string so that it used the short IP address for IPv6
addresses.
Finally, we have some code that takes a start & end IP address and gives
you the minimum number of subnets in that range. Right now this code
always excludes reserved networks but we can make that optional easily
enough.
Given you were already writing a bunch of wrappers around NetAddr::IP,
why did you decide to use Net::IP for ip_inttobin and ip_bintoip?
(ip_inttobin is basically just $NAIP->bigint->as_bin with some extra
formatting.)
We did, actually, but a co-worker recently pointed out that we could just
wrap NetAddr::IP to represent a single IP as well, so we'll probably merge
his branch which does this.
Why would I want to stop using NetAddr::IP and switch to these modules
instead? Are there any reasons that I wouldn't want to switch? (I'm
curious about these because I too wrote some wrappers around
NetAddr::IP. We use ours for fun stuff like generating large DHCP
configuration files from network information stored in a database. If I
ever get around to genericizing it, I'll be sure to release on CPAN
because someone else might also find it useful.)
Well, you wouldn't necessarily want to switch yet. It's not really a
complete wrapper, but it could be made so pretty quickly with some
additional delegation.
The main thing our distro provides besides the above is separate modules
for representing IP addresses and subnets, where the two modules interact.
So $subnet->first returns an IP address object (not a /32 or /128 subnet).
And our API is a bit less crufty and weird.
-dave
/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/