Module Domain

This module implements the class AbstractDomain and some derived classes, which encapsulate a set of physical addresses.

The class InetDomain implements IPv4 addresses, and IP segments represented in the form A.B.C.D/M, where A.B.C.D is the network address, and M specifies the number of ones in the netmask.

Imported modules

Class AbstractDomain

An address domain encapsulates an address type (AF_INET, AF_INET6 etc) and provides functions to parse and compare these addresses. This functionality is primarily used by Zone classes (see the module Zone), and the PacketFilter classes (see the module IPChains)

Attributes

Table 4-23. Attributes for class AbstractDomain

family address family this domain uses

Constructor __init__

Constructor initializing an AbstractDomain instance.

Synopsis

__init__ ( self )

Description

This constructor is basically empty and does nothing.

Arguments

Table 4-24. Arguments for AbstractDomain.__init__()

selfthis instance

Method __cmp__

Function to compare two domains.

Synopsis

__cmp__ ( self,  other )

Description

This function is a placeholder and is to be overridden by derived classes. It should return -1, 0 and 1 as described in the Python documentation.

Arguments

Table 4-25. Arguments for AbstractDomain.__cmp__()

selfthis instance
otherinstance to compare to

Exceptions

  • NotImplementedError

Class InetDomain

A class representing internet addresses. The inet objects are comparable, comparison means "contains", "equal to" and "contained by". The comparison can raise ValueError for incomparable ip addresses.

Attributes

Table 4-26. Attributes for class InetDomain

mask_bitsnumber of bits in the netmask
mask netmask in network byte order
ip network addresss in network byte order

Constructor __init__

Initializes an InetDomain instance

Synopsis

__init__ ( self,  addr )

Description

Parses the argument addr and fills in attributes accordingly.

Arguments

Table 4-27. Arguments for InetDomain.__init__()

addrthe string representation of an address, or address range

Method __cmp__

Compare this instance to another.

Synopsis

__cmp__ ( self,  other )

Description

Compare this instance to another InetDomain instance or to a SockAddrInet instance using set inclusion on addresses. An address is less than another, if it's fully contained by other.

Arguments

Table 4-28. Arguments for InetDomain.__cmp__()

self this instance
otherthe other InetDomain object to compare to

Exceptions

  • ValueError

Returns

-1, 0, or 1

Method __str__

Returns the string representation of this instance.

Synopsis

__str__ ( self )

Description

Returns the string representation of this instance in the form address/mask.

Arguments

Table 4-29. Arguments for InetDomain.__str__()

selfthis instance

Returns

string

Method broadcast

Calculate the broadcast address of this domain

Synopsis

broadcast ( self )

Description

Return the broadcast address of this domain calculated based on attributes.

Arguments

Table 4-30. Arguments for InetDomain.broadcast()

selfthis instance

Returns

the broadcast address in network byte order

Method netaddr

Calculate the network address of this domain.

Synopsis

netaddr ( self )

Description

Return the network address of this domain.

Arguments

Table 4-31. Arguments for InetDomain.netaddr()

selfthis instance

Returns

ip address in network byte order

Method netmask

Calculate netmask of this domain.

Synopsis

netmask ( self )

Description

Calculates and returns the netmask of this domain as an integer in network byte order.

Arguments

Table 4-32. Arguments for InetDomain.netmask()

selfthis instance

Returns

the network mask as ip in network byte order