Files for 2.1b1 distribution.
[python/dscho.git] / Doc / mac / libmacdnr.tex
blobefd80d4a274b32207ed4c7be106131fb4b81e880
1 \section{\module{macdnr} ---
2 Interface to the Macintosh Domain Name Resolver}
4 \declaremodule{builtin}{macdnr}
5 \platform{Mac}
6 \modulesynopsis{Interfaces to the Macintosh Domain Name Resolver.}
9 This module provides an interface to the Macintosh Domain Name
10 Resolver. It is usually used in conjunction with the \refmodule{mactcp}
11 module, to map hostnames to IP addresses. It may not be available in
12 all Mac Python versions.
13 \index{Macintosh Domain Name Resolver}
14 \index{Domain Name Resolver, Macintosh}
16 The \module{macdnr} module defines the following functions:
19 \begin{funcdesc}{Open}{\optional{filename}}
20 Open the domain name resolver extension. If \var{filename} is given it
21 should be the pathname of the extension, otherwise a default is
22 used. Normally, this call is not needed since the other calls will
23 open the extension automatically.
24 \end{funcdesc}
26 \begin{funcdesc}{Close}{}
27 Close the resolver extension. Again, not needed for normal use.
28 \end{funcdesc}
30 \begin{funcdesc}{StrToAddr}{hostname}
31 Look up the IP address for \var{hostname}. This call returns a dnr
32 result object of the ``address'' variation.
33 \end{funcdesc}
35 \begin{funcdesc}{AddrToName}{addr}
36 Do a reverse lookup on the 32-bit integer IP-address
37 \var{addr}. Returns a dnr result object of the ``address'' variation.
38 \end{funcdesc}
40 \begin{funcdesc}{AddrToStr}{addr}
41 Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
42 string. Returns the string.
43 \end{funcdesc}
45 \begin{funcdesc}{HInfo}{hostname}
46 Query the nameservers for a \code{HInfo} record for host
47 \var{hostname}. These records contain hardware and software
48 information about the machine in question (if they are available in
49 the first place). Returns a dnr result object of the ``hinfo''
50 variety.
51 \end{funcdesc}
53 \begin{funcdesc}{MXInfo}{domain}
54 Query the nameservers for a mail exchanger for \var{domain}. This is
55 the hostname of a host willing to accept SMTP\index{SMTP} mail for the
56 given domain. Returns a dnr result object of the ``mx'' variety.
57 \end{funcdesc}
60 \subsection{DNR Result Objects \label{dnr-result-object}}
62 Since the DNR calls all execute asynchronously you do not get the
63 results back immediately. Instead, you get a dnr result object. You
64 can check this object to see whether the query is complete, and access
65 its attributes to obtain the information when it is.
67 Alternatively, you can also reference the result attributes directly,
68 this will result in an implicit wait for the query to complete.
70 The \member{rtnCode} and \member{cname} attributes are always
71 available, the others depend on the type of query (address, hinfo or
72 mx).
75 % Add args, as in {arg1, arg2 \optional{, arg3}}
76 \begin{methoddesc}[dnr result]{wait}{}
77 Wait for the query to complete.
78 \end{methoddesc}
80 % Add args, as in {arg1, arg2 \optional{, arg3}}
81 \begin{methoddesc}[dnr result]{isdone}{}
82 Return \code{1} if the query is complete.
83 \end{methoddesc}
86 \begin{memberdesc}[dnr result]{rtnCode}
87 The error code returned by the query.
88 \end{memberdesc}
90 \begin{memberdesc}[dnr result]{cname}
91 The canonical name of the host that was queried.
92 \end{memberdesc}
94 \begin{memberdesc}[dnr result]{ip0}
95 \memberline{ip1}
96 \memberline{ip2}
97 \memberline{ip3}
98 At most four integer IP addresses for this host. Unused entries are
99 zero. Valid only for address queries.
100 \end{memberdesc}
102 \begin{memberdesc}[dnr result]{cpuType}
103 \memberline{osType}
104 Textual strings giving the machine type an OS name. Valid for ``hinfo''
105 queries.
106 \end{memberdesc}
108 \begin{memberdesc}[dnr result]{exchange}
109 The name of a mail-exchanger host. Valid for ``mx'' queries.
110 \end{memberdesc}
112 \begin{memberdesc}[dnr result]{preference}
113 The preference of this mx record. Not too useful, since the Macintosh
114 will only return a single mx record. Valid for ``mx'' queries only.
115 \end{memberdesc}
117 The simplest way to use the module to convert names to dotted-decimal
118 strings, without worrying about idle time, etc:
120 \begin{verbatim}
121 >>> def gethostname(name):
122 ... import macdnr
123 ... dnrr = macdnr.StrToAddr(name)
124 ... return macdnr.AddrToStr(dnrr.ip0)
125 \end{verbatim}