[Python-Dev] PEP 3144 review.

Andrew McNamara andrewm at object-craft.com.au
Fri Sep 18 06:26:19 CEST 2009

>On Fri, 18 Sep 2009 11:04:46 am Andrew McNamara wrote:
>> >To a non-specialist, "the network address" is ambiguous. There are
>> > many addresses in a network, and none of them are the entire
>> > network. It's like saying, given a list [2, 4, 8, 12], what's "the
>> > list item"?
>> A "network address" is an IP address and mask, but I understand your
>> confusion - we're mixing terminology from disperate domains. In my
>> postings, I have tried to refer to Network (a containter) and Address
>> (an item).
>So to clarify, how many different things which need to be handled are 
>1 IP address  -- a 32 bit (IPv4) or 128 bit (IPv6) number


>2 Netmask -- a bit mask of the form 111..100..0

I don't think there's much to be gained by exposing a Netmask object,
although other objects might have a .netmask property returning an
IPAddress instance. Where we expose a netmask, it should be as an
Address instance (or maybe a subclass with additional restrictions).

>3 Network address -- the lowest address in a network, and equal 
>  to (defined by?) the bitwise-AND of any address in the network 
>  with the network's netmask

This idea of a "network address" being simply an IP address is in error - 
a network address was always an address and a mask, however in the
days prior to CIDR, the mask was implicitly specified by the class of
the network.

>4 Host address -- the part of the IP address that is not masked 
>  by the netmask

Well, yes, but I don't think we need an entity representing that.

>5 Broadcast address -- the highest address in a IPv4 network

Yes, but again, we don't need an entity - as with the netmask, when
exposed, it should just be an Address instance (or subclass thereof).

>6 Network -- a range of IP address

Yes, although not an arbitrary or discontinuous range of address.

Really, I think we just need two entities (per protocol):

 Address (& maybe AddressWithMask)

   * If no mask is specified, this is just the IP address.
   * If a mask is specified, then it gains a .network property returning a
     Network instance. It probably should also have a .netmask property
     containing an Address instance.


   * Has an IP address with netmask 
   * for consistency's sake, masked address bits are not allowed
   * behaves like a read-only container wrt Addresses

So, you want to represent an interface on your host:

  >>> if_addr = IPv4Address('')

from this, you could get:

  >>> if_addr.address
  >>> if_addr.netmask
  >>> if_addr.broadcast
  >>> if_addr.network

you might also have an address for the default gateway:

  >>> router_addr = IPv4Address('')
  >>> router_addr in if_addr.network


  >>> router_addr = IPv4Address('')
  >>> router_addr in if_addr.network

Or maybe you've subneted your LAN:

  >>> IPV4Network('') in IPv4Network('')
  >>> IPV4Network('') in IPv4Network('')


  >>> IPV4Network('') in IPv4Network('')

This suggests the natural behaviour if the Address mask doesn't fit in the

  >>> IPv4Address('') in IPv4Network('')

Andrew McNamara, Senior Developer, Object Craft

More information about the Python-Dev mailing list