Package nss :: Module io :: Class AddrInfo
[hide private]
[frames] | no frames]

type AddrInfo

object --+
         |
        AddrInfo

AddrInfo(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)

An object used to encapsulate network address information for a specific host.

After successful initialization the AddrInfo object will contain an ordered sequence of NetworkAddress objects which may be accessed via iteration or indexing. It is suggested you try connecting with the each NetworkAddress object in sequential order until one succeeds.

Example Usage:

try:
    addr_info = io.AddrInfo(hostname)
except Exception, e:
    print "ERROR: could not resolve address for %s" % hostname
    return
for net_addr in addr_info:
    net_addr.port = port
    sock = io.Socket(net_addr.family)
    try:
        sock.connect(net_addr, timeout=io.seconds_to_interval(1))
        return
    except Exception, e:
        pass
 print "ERROR: could not connect to %s at port %d" % (hostname, port)

Note, the NSPR interface to getaddrinfo() does not provide a way to select just IPv6 addresses. The solution is filter them yourself, e.g.:

for net_addr in addr_info:
   if net_addr.family != io.PR_AF_INET6: continue
Instance Methods [hide private]
 
__getitem__(x, y)
x[y]
 
__init__(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__len__(x)
len(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__str__(x)
str(x)
Properties [hide private]
  canonical_name
Returns the canonical name associated with the IP address or None if not known
  hostname
Returns the hostname this object was initialized from
Method Details [hide private]

__init__(hostname, family=PR_AF_UNSPEC, flags=PR_AI_ADDRCONFIG)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Parameters:
  • hostname (str or unicode object) - Either a hostname or an address string (dotted-decimal for IPv4 or a hex string for IPv6.
  • family (int) -
    May be:
    • PR_AF_UNSPEC
    • PR_AF_INET.
  • flags (int) -
    May be either:
    • PR_AI_ADDRCONFIG
    • PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME

    Include PR_AI_NOCANONNAME to suppress the determination of the canonical name corresponding to hostname.

Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__str__(x)
(Informal representation operator)

 
str(x)
Overrides: object.__str__