context Used to return the pointer to an opaque structure. The caller passes the address of a pointer (decl: getdns_context *context; passed as &context) which will be populated as a result of returning from the function. The result is a newly allocated and initialized context (if there are no errors). In the getdns_destroy_context function this is the context whose associated memory will be released.
Many calls in the DNS API require a DNS context. A DNS context contains the information that the API needs in order to process DNS calls, such as the locations of upstream DNS servers, DNSSEC trust anchors, and so on. The internal structure of the DNS context is opaque, and might be different on each OS. When a context is passed to any function, it must be an allocated context; the context must not be NULL.
A typical application using this API doesnt need to know anything about contexts. Basically, the application creates a default context, uses it in the functions that require a context, and then deallocates it when done. Context manipulation is available for more DNS-aware programs, but is unlikely to be of interest to applications that just want the results of lookups for A, AAAA, SRV, and PTR records.
It is expected that contexts in implementations of the API will not necessarily be thread-safe, but they will not be thread-hostile. A context should not be used by multiple threads: create a new context for use on a different thread. It is just fine for an application to have many contexts, and some DNS-heavy applications will certainly want to have many even if the application uses a single thread.
When the context is used in the API for the first time and set_from_os is 1, the API starts replacing some of the values with values from the OS, such as those that would be found in res_query(3), /etc/resolv.conf, and so on, then proceeds with the new function. Some advanced users will not want the API to change the values to the OSs defaults; if set_from_os is 0, the API will not do any updates to the initial values based on changes in the OS. For example, this might be useful if the API is acting as a stub resolver that is using a specific upstream recursive resolver chosen by the application, not the one that might come back from DHCP.
Upon successful completion each of these functions return GETDNS_RETURN_GOOD , otherwise the following error values are returned:
GETDNS_RETURN_GENERIC_ERROR memory allocation failed or some other untoward thing happened while initializing the context
GETDNS_RETURN_BAD_CONTEXT if the context pointer is invalid (getdns_context_destroy)
The getdns_dict returned by getdns_context_get_api_information must be destroyed by the called and includes the following name/value pairs:
version_string a bindata containing a printable string of the version of the DNS API implemented by this library
implementation_string a bindata containing a printable string set by the implementation
resolution_type an int equal to GETDNS_RESOLUTION_RECURSING or GETDNS_RESOLUTION_STUB
all_context a getdns_dict with names for all the types of context, feed it to getdns_pretty_print_dict (3) for something easily readable
libgetdns(3), getdns_address(3), getdns_address_sync(3), getdns_context_set(3), getdns_context_set_context_update_callback(3), getdns_general(3), getdns_general_sync(3), getdns_hostname(3), getdns_hostname_sync(3), getdns_service(3), getdns_service_sync(3).
|getdns 0.9.0||GETDNS_CONTEXT (3)||December 2015|