From: Bryan Richardson Date: 2008-01-16T14:53:29+09:00 Subject: Re: Problem with IPAddr ------=_Part_19931_3525678.1200462816286 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Gary, Thanks for the reply. Here's what I get when I try something else: irb(main):001:0> require 'ipaddr' => true irb(main):002:0> net_1 = IPAddr.new("192.168.0.0/16") => # irb(main):003:0> net_2 = IPAddr.new("192.168.101.0/24") => # irb(main):004:0> net_1.include?(net_2) => true irb(main):005:0> net_2.include?(net_1) => false irb(main):006:0> Makes sense I guess. Is there any way to tell IPAddr to look at it as a network instead of as an address? I have a situation where I may come across an address (ending in .0, so defining a network) where the netmask isn't given, so I assign it as a small network (say /29). Later on I may come across it again, this time with the netmask defined (say /16), and I want to merge the first one into the second one. Therefore, each time I add a new network to my database, I compare it to the existing ones to see if any should be merged. Any suggestions? Thanks!! -- BTR On Jan 15, 2008 10:32 PM, Gary Wright wrote: > > On Jan 16, 2008, at 12:02 AM, Bryan Richardson wrote: > > > Hello all, > > > > I'm having a problem with IPAddr, and I'm hoping someone can > > explain it to > > me. I've done the following test, and I get the results shown below. > > > > irb(main):001:0> require 'ipaddr' > > => true > > irb(main):002:0> net_1 = IPAddr.new("192.168.0.0/16") > > => # > > irb(main):003:0> net_2 = IPAddr.new("192.168.0.0/24") > > => # > > irb(main):004:0> net_1.include?(net_2) > > => true > > irb(main):005:0> net_2.include?(net_1) > > => true > > irb(main):006:0> > > It is because include? is treating its argument as an address not as > a network. The subnet mask of the argument is ignored. So > net_2.include?(net_1) is really asking whether the first address of > net_1 (192.168.0.0) is contained in net_2 and that is true. > > Gary Wright > > > ------=_Part_19931_3525678.1200462816286--