[Python-Dev] PEP 3144 review. (original) (raw)

R. David Murray rdmurray at bitdance.com
Thu Sep 17 00:27:28 CEST 2009


On Thu, 17 Sep 2009 at 09:59, Greg Ewing wrote:

Nick Coghlan wrote:

Or, to put it another way, given an arbitrary host in a network (e.g. your own machine or the default gateway) and the netmask for that network, calculate the network address. Some people have claimed that the gateway address of a network isn't necessarily the zero address in that network. If that's true, then you can't calculate the network address from a host address and a netmask -- there isn't enough information. Furthermore, an IPNetwork object needs to be able to represent a network address whose address part contains bits that aren't in the mask.

A 'gateway' is an IP (ie: host) in a network to which you route packets for delivery elsewhere. That's a very different thing from the 'network number' (or 'network address' or 'network zero' or 'network identifier' or whatever you want to call it). Any IP in a network can be a gateway IP, and in many networks there is more than one gateway (and thus the need for routing tables...)

A network is conventionally represented by an IP address in which the bits corresponding to the one bits in the netmask are set to zero, plus the netmask. That IP with the bits set to zero is the 'network number' or zero for the network, and it is almost never used as the address for a host in the network. Thus it would be very surprising to find it being used as a gateway address.

There is no reason why an IPNetwork object should record any bits from the portion of the IP address that are covered by the mask bits. To do otherwise is to conflate Networks with individual IPs, which is what got IPAddr rejected the first time around. (And for those of you who don't know/remember, I was initially an IPAddr booster in its original incarnation, because I come from a network engineering background.)

This existence of this kind of confusion is why I voted +1 for the IPNetwork constructor rejecting input with non-zero bits covered by the mask, and a separate constructor method to return the network object representing the network that a given IP address is in when a given mask is applied to it. (Which is easily computed by applying the mask to the IP.)

--David



More information about the Python-Dev mailing list