[Python-Dev] PEP 3144 review.

python-3000 at udmvt.ru python-3000 at udmvt.ru
Wed Sep 16 10:26:30 CEST 2009


On Tue, Sep 15, 2009 at 09:35:13PM +0200, Sebastian Rittau wrote:
> On Tue, Sep 15, 2009 at 01:16:06PM -0400, Scott Dial wrote:
> 
> > I have to concur with the opinions above. I was very confused by the
> > following error:
> > 
> > >>> addr = ipaddr.IPAddress("10.1.2.3/255.255.240.0")
> > ...
> > ipaddr.IPAddressIPValidationError: '98.223.189.24/255.255.240.0' is not
> > a valid address (hint, it's probably a network)
> > 
> > Because, it *is* a address of a host on a network.
> 
> To me, 10.1.2.3/255.255.240.0 is not a host address, but specifies a
> network. I.e., 10.1.2.3/255.255.240.0 == 10.1.0.0/255.255.240.0 ==
> 10.1.35.200/20.
We shouldn't invent another bicycle here. It is a host address, that ALSO
specifies a network mask, that is not /32. Mask /32 just may be omitted when
written, but assumed, when stored by computer.

What you talk about is "address with mask". It is just IP address plus mask
information. IP address and mask just written together, one after another.
You MAY use mask to extract network part from an address, and have a "set" of
IP addresses, or range of IP addresses, or "network" as you say.
But you are not forced to do that with "MUST" statement, because you may also
use mask and IP address to compute widely used default value for a "broadcast"
address, or you may extract "host" part from the whole IP address.

There is no semantical difference between IPAddress for hosts and IPAddress for
networks, look at 'inet' type of PostgreSQL. Python shouldn't have separate
types for that - it is stupid, people will say 'python programmers are lamers'.
If you need only one IP address - you write AA.BB.CC.DD[/32] or /255.255.255.255
and the mask value may be omitted here. If you need to specify a larger range of
IP addresses, you specify another mask value, that is simple.


> 
> > >>> net = ipaddr.IPNetwork("10.1.2.3/255.255.240.0")
> > 
> > But then, I was dumbfounded as to how I could get the gateway IP from
> > this IPNetwork object.
> 
> Well, you can't. There is no way to determine a gateway, without querying
> the network topology. This is clearly outside the scope of this module.
> The only two known host addresses of a network are the network address
> (10.1.0.0 in the example you gave) and the broadcast address (10.1.15.255).
> 
> > It took me a while to figure out that you can
> > iterate over IPNetwork instances:
> > 
> > >>> gateway = net[1]
> > 
> > I was then confused, because:
> > 
> > >>> print(type(gateway))
> > <class 'ipaddr.IPv4Address'>
> > 
> > Which sorta blew my mind.. I fully expected to receive an IPNetwork back
> > from that operation. It is unclear to me why the network information
> > gets chucked by that operation.
> 
> This makes perfect sense to me. An IP network consists of a list of IP
> addresses. Returning /32 networks seems kind of pointless to me.
Why? What differ IP Host address from IP Network address with mask /32?
Don't say "they have different python classes".
Well, I know, that an element is not a set containing only that element.
But that is about mathematical objects. What difference between /32 IP Network
and IP Host for Python?

Why IPNetwork can't be used where IPAddress is used?
When you only need IP address, you only use address part and ignore mask.
Why IPAddress can't be used where IPNetwork is accepted?
It is just IPNetwork with /32 mask.

It is counterintuitive for me, network administrator.

> 
> > I foresee having to work around that in
> > real applications by doing something obnoxious like:
> > 
> > >>> actual_gateway = ipaddr.IPNetwork("%s/%s" % (gateway, addr.netmask))
> 
> But a gateway is not an IP address plus hostmask. A gateway is just a single
> IP address. What is the use of adding a hostmask to the gateway IP address
> or some other IP address inside the network?
Just to specify an address together with a mask, for short. It is widespread.
People are used to it.
When a gateway address written with a mask, it fully specifies you IP stack
configuration, it specifies (when computed as usual):
   1. netmask
   2. your subnetwork address
   3. host address
   4. address of default route
   5. subnetwork broadcast address
   6. I don't know, maybe something else?
   7. Oh, yes, it shows you the range of IP addresses, available for your use,
      if it was your subnetwork.
So, what is better to write on network diagrams or other documentation, those
five data pieces or just one gateway-with-a-mask?


> 
>  - Sebastian
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-3000%40udmvt.ru

-- 
Alexey S.


More information about the Python-Dev mailing list