[Python-Dev] PEP 3144 review.

Daniel Stutzbach daniel at stutzbachenterprises.com
Thu Sep 17 00:31:27 CEST 2009


On Wed, Sep 16, 2009 at 4:59 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> Some people have claimed that the gateway address of a
> network isn't necessarily the zero address in that network.
>

I'll go further: I don't think it's even legal for the gateway address to be
the zero address of the network (and I used to program the embedded software
in routers for a living :) ).


> If that's true, then you *can't* calculate the network
> address from a host address and a netmask -- there isn't
> enough information.


In a router or operating system kernel, an IPv4 address or netmask is stored
in a 32-bit unsigned integer.  Host addresses, network addresses, and
netmasks satisfy the following properties, where & is the bitwise-AND
operation:

network address & netmask == network address
host address & netmask == network address of that host

A gateway is just a host that will forward packets.  A gateway address has
the same properties as a host address and isn't the same as the zero
address.

Every host has a routing table that contains a list of (network address,
gateway, netmask) tuples.  To see the list, just run "/sbin/route -n" on any
Linux system (and most other Unixes; root is not typically required) or
"route print" on a Windows system.

To route a packet, the operating system essentially performs the following
algorithm:

def find_gateway_for_destination(destination_address):
    for (network_address, gateway, netmask) in
list_of_routing_table_entires:
        if network_address == destination_address & netmask:
            return gateway
    raise DestinationUnreachable

Furthermore, an IPNetwork object
> needs to be able to represent a network address whose
> address part contains bits that aren't in the mask.
>

Network addresses never contain bits that aren't in the mask (due to the
rule: "network address & netmask == network address").

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090916/c15f752a/attachment.htm>


More information about the Python-Dev mailing list