[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Standardlib "ipaddr.rb"

e

1/7/2005 7:37:00 PM

> Lähettäjä: Markus Werner <markus.werner@wobcom.de>
> Aihe: Re: Standardlib "ipaddr.rb"
>
> On Wednesday 05 January 2005 14:59, Florian G. Pflug wrote:
> Hi Florian,
>
> > IpNetwork: Represents a network/ip-prefix, e.g.
> > 192.168.0.0/16, or
> > 192.168.1.0/24, but not 192.168.1.1/24, because it's not a
> > network.
> > IpAddress: Represents an ip-address, without netmask
> > IpInterface: Represents an ip-address in a certain network, e.g
> > 192.168.1.1/24.
> > I'm not sure if 192.168.0.0 is a valid ip-address in the
> > 192.168.0.0/24 network...
>
> Just to think about : 192.168.1.1/32 or fe00::1/128 is a valid notation for a
> single IP Address.

Not really. There is no such IP address as 192.168.1.1/32. There's
just the IP address 192.168.1.1 and the subnet it may be a part of.

> I will write my own Classes for IP Addresses now, and hope that the IPAddr lib
> get changed in the future.

I understand the confusion, but the proper solution is not to change
IPAddr to store your notation but to create two separate classes,
IPAddr and Subnet (or CIDR or whatever). The reason for this is that
any entity that needs to know what subnet should be used to interpret
a given IP address should /already know/ what that subnet is.

E



3 Answers

Markus Werner

1/10/2005 9:49:00 AM

0

Dear "E S",


thanks for you answer.

> Not really. There is no such IP address as 192.168.1.1/32. There's
> just the IP address 192.168.1.1 and the subnet it may be a part of.

So far I know it is a valid address.
I'm the opionion that nowadays a IP Address is only usefull for networking if
you know the netmask too. So I handle write down IP's always as
172.17.3.5/prefix_length, which could be also '32'. But sure I'm a admin, so
I'm lazy. And in clear cases I don't write /32 at all.


> I understand the confusion, but the proper solution is not to change
> IPAddr to store your notation but to create two separate classes,
> IPAddr and Subnet (or CIDR or whatever). The reason for this is that
> any entity that needs to know what subnet should be used to interpret
> a given IP address should /already know/ what that subnet is.

Hmmm...
Maybe we think a bit different. I would use IPAddr for storing IPaddresses and
get infomation based on this addresses, like Networkaddress aso.
(Why should I store the same thing twice, if I have already an object who
knows about).

So I say it is still a failure that the IPAddress I gave to IPAddr is
converted automatically to a different value.
And in anycase I state that IPAddr, should reject wrong values and not change
a value to different one.

I would like to have a clear interface. That does things the way, a user of
the class expect.
----
ipaddr = IPAddr.new('192.168.0.3/24')
ipaddr.ip => 192.168.0.3
ipaddr.cidr => 192.168.0.3/24
ipaddr.prefix => 192.168.0.0/24
ipaddr.net => 192.168.0.0
ipaddr.mask => 255.255.255.0
ipaddr.prefix_length => 24
ipaddr.bc => 192.168.0.255 #IPv4 only If called on IPv6 it should raise an
error.

Some more method (Brainstorming)
ipaddr.net_size? => 256
ipaddr.nodes_available? = 254
# More methods ...

########
ipaddr = IPAddr.new('192.168.0.3/32')
ipaddr.ip => 192.168.0.3
ipaddr.cidr => 192.168.0.3/32
ipaddr.prefix => 192.168.0.3/32 or nil or rais an error # What is technical
right and what would the user expect ? This is here the question.

ipaddr.net => nil or rais an error? # I'm not sure at the moment
ipaddr.bc => same as above
ip.addr.mask => 255.255.255.255
ipaddr.prefix_length => 32


and so on
-----

A other Question: "What should the Class to with a /31 prefix IPv4?"


IMHO this interface would fullfill both opinions mentioned in this thread,
and it is clean and don't do things, that are unexpectable.

regards

Markus


Simon Barnes

1/10/2005 7:33:00 PM

0

It may help to consider that notwithstanding its name, ipaddr.rb is a module
to perform operations on subnets. Within it, IP addresses are converted to
subnets with all-ones netmasks. So when handed something like
192.168.1.2/24, it has to decide what subnet was meant, and simply masks out
the host part to obtain subnet 192.168.1.0/24, which IMO is a reasonable
thing to do. Specifying either 192.168.1.2 or 192.168.1.2/32 will result in
an object which will match only a single IP address. If there was interest
in manipulating IP addresses with particular netmasks, then this would
indeed require a module with different functionality.

I would very much like to see a cidr method in ipaddr though. Will have to
try to contact the maintainer.

Simon


Boyd Adamson

1/10/2005 9:25:00 PM

0

Markus Werner <markus.werner@wobcom.de> writes:

> Dear "E S",
> thanks for you answer.
>
>> Not really. There is no such IP address as 192.168.1.1/32. There's
>> just the IP address 192.168.1.1 and the subnet it may be a part of.
>
> So far I know it is a valid address.

This is just not true. Try "ping 192.168.1.1/32".

> I'm the opionion that nowadays a IP Address is only usefull for
> networking if you know the netmask too.

Also not true. The only netmask a machine needs to know is its own, to
determine if a destination machine is on-link or not. Remember that it's
far more common to handle the IP addresses of remote machines, where we
don't neccesarily know (or need) what their netmask is.

The DNS doesn't return the netmask of a remote machine, only the IP
address. The internet seems to still work mostly ;-)

> So I handle write down IP's always as 172.17.3.5/prefix_length, which
> could be also '32'. But sure I'm a admin, so I'm lazy. And in clear
> cases I don't write /32 at all.

IP addresses as we know them existed long before the "/yy" prefix
notation was developed. It's certainly convenient but it's only needed
for local machine configuration. It's also used for route entries,
firewall rules, access lists, etc. But in all those cases it's a form of
shorthand, and never a part of the IP address.

>> I understand the confusion, but the proper solution is not to change
>> IPAddr to store your notation but to create two separate classes,
>> IPAddr and Subnet (or CIDR or whatever). The reason for this is that
>> any entity that needs to know what subnet should be used to interpret
>> a given IP address should /already know/ what that subnet is.
>
> Hmmm... Maybe we think a bit different. I would use IPAddr for
> storing IPaddresses and get infomation based on this addresses, like
> Networkaddress aso. (Why should I store the same thing twice, if I
> have already an object who knows about).
>
> So I say it is still a failure that the IPAddress I gave to IPAddr is
> converted automatically to a different value. And in anycase I state
> that IPAddr, should reject wrong values and not change a value to
> different one.
>
> <snip>

I'm inclined to agree that a library for handling IP addresses should
provide some support for handling netmasking, but that functionality
doesn't belong in a class representing IP addresses. An IP address class
should represent just that - the information needed to establish a TCP
session for example. Subnets are NOT IP addresses. Netmasks are NOT IP
addresses.

Just my $0.02