sandbox/loewis / Doc / libmacdnr.tex

The branch 'legacy-trunk' does not exist.
Full commit

\section{Built-in Module \sectcode{macdnr}}

This module provides an interface to the Macintosh Domain Name
Resolver.  It is usually used in conjunction with the \var{mactcp}
module, to map hostnames to IP-addresses.  It may not be available in
all Mac Python versions.

The \code{macdnr} module defines the following functions:

\renewcommand{\indexsubitem}{(in module macdnr)}

Open the domain name resolver extension.  If \var{filename} is given it
should be the pathname of the extension, otherwise a default is
used.  Normally, this call is not needed since the other calls will
open the extension automatically.

Close the resolver extension.  Again, not needed for normal use.

Look up the IP address for \var{hostname}.  This call returns a dnr
result object of the ``address'' variation.

Do a reverse lookup on the 32-bit integer IP-address
\var{addr}.  Returns a dnr result object of the ``address'' variation.

Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
string.  Returns the string.

Query the nameservers for a \code{HInfo} record for host
\var{hostname}.  These records contain hardware and software
information about the machine in question (if they are available in
the first place).  Returns a dnr result object of the ``hinfo''

Query the nameservers for a mail exchanger for \var{domain}.  This is
the hostname of a host willing to accept SMTP mail for the given
domain.  Returns a dnr result object of the ``mx'' variety.

\subsection{dnr result object}

Since the DNR calls all execute asynchronously you do not get the
results back immediately.  Instead, you get a dnr result object.  You
can check this object to see whether the query is complete, and access
its attributes to obtain the information when it is.

Alternatively, you can also reference the result attributes directly,
this will result in an implicit wait for the query to complete.

The \var{rtnCode} and \var{cname} attributes are always available, the
others depend on the type of query (address, hinfo or mx).

\renewcommand{\indexsubitem}{(dnr result object method)}

% Add args, as in {arg1\, arg2 \optional{\, arg3}}
Wait for the query to complete.

% Add args, as in {arg1\, arg2 \optional{\, arg3}}
Return 1 if the query is complete.

\renewcommand{\indexsubitem}{(dnr result object attribute)}

The error code returned by the query.

The canonical name of the host that was queried.

At most four integer IP addresses for this host.  Unused entries are
zero.  Valid only for address queries.

Textual strings giving the machine type an OS name.  Valid for hinfo

The name of a mail-exchanger host.  Valid for mx queries.

The preference of this mx record.  Not too useful, since the Macintosh
will only return a single mx record.  Mx queries only.

The simplest way to use the module to convert names to dotted-decimal
strings, without worrying about idle time, etc:
>>> def gethostname(name):
...     import macdnr
...     dnrr = macdnr.StrToAddr(name)
...     return macdnr.AddrToStr(dnrr.ip0)