Presently, the DNS system uses dns.c as its backend. This code is included in the ratchet package and is current as of Jan 14, 2011. QueryingSubmitting a query of a specific type (e.g. MX or AAAA) is done using the
local rec = ratchet.dns.query("emailsrvr.com", "mx") print(rec[10]) -- "mx1.emailsrvr.com." print(rec[20]) -- "mx2.emailsrvr.com."
local rec = ratchet.dns.query_all("emailsrvr.com", {"aaaa", "a"}) -- rec.a => {[1] = <userdata>} -- rec.aaaa => nil -- rec.aaaa_error => "emailsrvr.com has no AAAA record" IPv4 A Records ("a" Query Type)Until IPv6 takes over, these will be the most useful queries. It does a simple
A record lookup on a hostname to find its associated IP address. This is, for
example, what a web browser would do to find out where to connect, given a
domain name like "www.google.com". Results are given in a numbered Lua table
in the order they are received, as local rec = ratchet.dns.query("ratchet.icgood.net", "a") IPv6 AAAA Records ("aaaa" Query Type)If a hostname has an AAAA record, it will be the associated IPv6 address.
During the migration to IPv6, if a AAAA record is not returned the client
should call back to A records. Results are given in a numbered Lua table in
the order they are received, as local rec = ratchet.dns.query("ratchet.icgood.net", "aaaa") PTR Records ("ptr" Query Type)Performs a "reverse" lookup of an IPv4/IPv6 string, for an associated hostname. Results are given in a numbered Lua table in the order they are received, as hostname strings. local rec = ratchet.dns.query("74.205.6.223", "ptr") -- rec[1] => "emailsrvr.com." MX Records ("mx" Query Type)Looks up prioritized mail routing records of a hostname. The results are acceptable next-hops for mail intended for the domain. These records should generally be avoided in favor of a mail server running a configured MTA to deliver mail to the outside world. Results are given as a table keyed on priority number (e.g. 10, 20, ...) with the value being a next-hop address. The address will likely be a hostname that will require an A/AAAA lookup. The result table for an MX query has a special method local rec = ratchet.dns.query("ratchet.icgood.net", "mx") TXT Records ("txt" Query Type)Looks up a text field associated with a domain name. Often, this field is used for anti-abuse records such as SPF. Results are given as a numbered Lua table in the order they are received, as arbitrary strings. local rec = ratchet.dns.query("emailsrvr.com", "txt") -- rec[1] => "v=spf1 ip4:207.97.245.0/24 ip4:207.97.227.208/28 ...etc..." ErrorsIn exchange for usually being lightning-fast, DNS queries can and will fail
occasionally. For a call to local rec = ratchet.dns.query_all("ratchet.icgood.net", {"aaaa", "a"}) -- rec.aaaa => nil -- rec.aaaa_error => "ratchet.icgood.net has no AAAA record" If a query does not return from the DNS server, it is tries again at various intervals until finally failing or succeeding. During this time, the requesting thread will remain paused and other activity continues as usual. |
||||||
|