A getdns query (Context.address(), Context.hostname(), Context.service(), and Context.general()) returns a Result object. A Result object is only returned from a query and may not be instantiated by the programmer. It is a read-only object. Contents may not be overwritten or deleted.
It has no methods but includes the following attributes:
The status attribute contains the status code returned by the query. Note that it may be the case that the query can be successful but there are no data matching the query parameters. Programmers using this API will need to first check to see if the query itself was successful, then check for the records returned.
The status attribute may have the following values:
At least one response was returned
Queries for the name yielded all negative responses
All queries for the name timed out
The context setting for getting only secure responses was specified, and at least one DNS response was received, but no DNS response was determined to be secure through DNSSEC.
The answer_type attribute contains the type of data that are returned (i.e., the namespace). The answer_type attribute may have the following values:
The WINS name service (some reference needed)
The value of canonical_name is the name that the API used for its lookup. It is in FQDN presentation format.
If the call was address(), the attribute just_address_answers (a list) is non-null. The value of just_address_answers is a list that contains all of the A and AAAA records from the answer sections of any of the replies, in the order they appear in the replies. Each item in the list is a dict with at least two names: address_type (a string whose value is either “IPv4” or “IPv6”) and address_data (whose value is a string representation of an IP address). Note that the dnssec_return_only_secure extension affects what will appear in the just_address_answers list. Also note if later versions of the DNS return other address types, those types will appear in this list as well.
The replies_full attribute is a Python dictionary containing the entire set of records returned by the query.
The following lists the status codes for response objects. Note that, if the status is that there are no responses for the query, the lists in replies_full and replies_tree will have zero length.
The top level of replies_tree can optionally have the following names: canonical_name, intermediate_aliases (a list), answer_ipv4_address answer_ipv6_address, and answer_type (an integer constant.).
If the call was address(), the top level of replies_tree has an additional name, just_address_answers (a list). The value of just_address_answers is a list that contains all of the A and AAAA records from the answer sections of any of the replies, in the order they appear in the replies. Each item in the list is a dict with at least two names: address_type (a string whose value is either “IPv4” or “IPv6”) and address_data (whose value is a string representation of an IP address). Note that the dnssec_return_only_secure extension affects what will appear in the just_address_answers list. Also note if later versions of the DNS return other address types, those types will appear in this list as well.
The API can make service discovery through SRV records easier. If the call was service(), the top level of replies_tree has an additional name, srv_addresses (a list). The list is ordered by priority and weight based on the weighting algorithm in RFC 2782, lowest priority value first. Each element of the list is a dictionary that has at least two names: port and domain_name. If the API was able to determine the address of the target domain name (such as from its cache or from the Additional section of responses), the dict for an element will also contain address_type (whose value is currently either “IPv4” or “IPv6”) and address_data (whose value is a string representation of an IP address). Note that the dnssec_return_only_secure extension affects what will appear in the srv_addresses list.
The validation_chain attribute is a Python list containing the set of DNSSEC-related records needed for validation of a particular response. This set comes as validation_chain (a list) at the top level of the response object. This list includes all resource record dicts for all the resource records (DS, DNSKEY and their RRSIGs) that are needed to perform the validation from the root up.
The names in each entry in the the replies_tree list for DNS responses include header (a dict), question (a dict), answer (a list), authority (a list), and additional (a list), corresponding to the sections in the DNS message format. The answer, authority, and additional lists each contain zero or more dicts, with each dict in each list representing a resource record.
The names in the header dict are all the fields from RFC 1035. They are: id, qr, opcode, aa, tc, rd, ra, z, rcode, qdcount, ancount, nscount, and arcount. All are integers.
The names in the question dict are the three fields from RFC 1035: qname, qtype, and qclass.
Resource records are a bit different than headers and question sections in that the RDATA portion often has its own structure. The other names in the resource record dictionaries are name, type, class, ttl, and rdata (which is a dict); there is no name equivalent to the RDLENGTH field. The OPT resource record does not have the class and the ttl name, but instead provides udp_payload_size, extended_rcode, version, do, and z.
The rdata dictionary has different names for each response type. There is a complete list of the types defined in the API. For names that end in “-obsolete” or “-unknown”, the data are the entire RDATA field. For example, the rdata for an A record has a name ipv4_address; the rdata for an SRV record has the names priority, weight, port, and target.
Each rdata dict also has a rdata_raw element. This is useful for types not defined in this version of the API. It also might be of value if a later version of the API allows for additional parsers. Thus, doing a query for types not known by the API still will return a result: an rdata with just a rdata_raw.
It is expected that later extensions to the API will give some DNS types different names. It is also possible that later extensions will change the names for some of the DNS types listed above.
For example, a response to a Context.address() call for www.example.com would look something like this:
{ # This is the response object
"replies_full": [ <bindata of the first response>, <bindata of the second response> ],
"just_address_answers":
[
{
"address_type": <bindata of "IPv4">,
"address_data": <bindata of 0x0a0b0c01>,
},
{
"address_type": <bindata of "IPv6">,
"address_data": <bindata of 0x33445566334455663344556633445566>
}
],
"canonical_name": <bindata of "www.example.com">,
"answer_type": GETDNS_NAMETYPE_DNS,
"intermediate_aliases": [],
"replies_tree":
[
{ # This is the first reply
"header": { "id": 23456, "qr": 1, "opcode": 0, ... },
"question": { "qname": <bindata of "www.example.com">, "qtype": 1, "qclass": 1 },
"answer":
[
{
"name": <bindata of "www.example.com">,
"type": 1,
"class": 1,
"ttl": 33000,
"rdata":
{
"ipv4_address": <bindata of 0x0a0b0c01>
"rdata_raw": <bindata of 0x0a0b0c01>
}
}
],
"authority":
[
{
"name": <bindata of "ns1.example.com">,
"type": 1,
"class": 1,
"ttl": 600,
"rdata":
{
"ipv4_address": <bindata of 0x65439876>
"rdata_raw": <bindata of 0x65439876>
}
}
]
"additional": [],
"canonical_name": <bindata of "www.example.com">,
"answer_type": GETDNS_NAMETYPE_DNS
},
{ # This is the second reply
"header": { "id": 47809, "qr": 1, "opcode": 0, ... },
"question": { "qname": <bindata of "www.example.com">, "qtype": 28, "qclass": 1 },
"answer":
[
{
"name": <bindata of "www.example.com">,
"type": 28,
"class": 1,
"ttl": 1000,
"rdata":
{
"ipv6_address": <bindata of 0x33445566334455663344556633445566>
"rdata_raw": <bindata of 0x33445566334455663344556633445566>
}
}
],
"authority": [ # Same as for other record... ]
"additional": [],
},
]
}
The return codes for all the functions are:
Good
Generic error
Badly-formed domain name in first argument
The context has internal deficiencies
Did not update the context
An attempt was made to cancel a callback with a transaction_id that is not recognized
A helper function for lists had an index argument that was too high.
A helper function for dicts had a name argument that for a name that is not in the dict.
A helper function was supposed to return a certain type for an item, but the wrong type was given.
A name in the extensions dict is not a valid extension.
One or more of the extensions have a bad format.
A query was made with a context that is using stub resolution and a DNSSEC extension specified.
Unable to allocate the memory required.
A required parameter had an invalid value.