Creating simple DNS servers

Typedefs

typedef void(* getdns_request_handler_t) (getdns_context *context, getdns_callback_type_t callback_type, getdns_dict *request, void *userarg, getdns_transaction_t request_id)
 

Functions

getdns_return_t getdns_context_set_listen_addresses (getdns_context *context, const getdns_list *listen_addresses, void *userarg, getdns_request_handler_t handler)
 
getdns_return_t getdns_reply (getdns_context *context, const getdns_dict *reply, getdns_transaction_t request_id)
 

Detailed Description

Typedef Documentation

◆ getdns_request_handler_t

typedef void(* getdns_request_handler_t) (getdns_context *context, getdns_callback_type_t callback_type, getdns_dict *request, void *userarg, getdns_transaction_t request_id)

The user defined request handler that will be called on incoming requests.

Definition at line 2239 of file getdns_extra.h.

Function Documentation

◆ getdns_context_set_listen_addresses()

getdns_return_t getdns_context_set_listen_addresses ( getdns_context context,
const getdns_list listen_addresses,
void *  userarg,
getdns_request_handler_t  handler 
)

Create a name server by registering a list of addresses to listen on and a user defined function that will handle the requests.

Parameters
contextThe context managing the eventloop that needs to be run to start serving.
listen_addressesA list of address dicts or bindatas that will be listened on for DNS requests. Both UDP and TCP transports will be used.
userargA user defined argument that will be passed to the handler untouched.
handlerThe user defined request handler that will be called with the request received in reply dict format. To reply to this request the function has to construct a response (or modify the request) and call getdns_reply() with the response and the with the request associated request_id. The user is responsible of destroying both the replies and the response. Beware that if requests are not answered by the function, by not calling getdns_reply() this will cause a memory leak. The user most use getdns_reply() with NULL as the response to not answer/cancel a request.
Returns
GETDNS_RETURN_GOOD on success or an error code on failure. On failure, the current set of listening addresses is left in place. Also, if there is overlap in listening_addresses between the active set and the newly given set, the ones in the active set will remain in their current condition and will not be closed and reopened, also all associated DNS transactions will remain.

◆ getdns_reply()

getdns_return_t getdns_reply ( getdns_context context,
const getdns_dict reply,
getdns_transaction_t  request_id 
)

Answer the request associated with a request_id that is received by a request handler

Parameters
contextThe context managing the eventloop that needs to be run to listen for and answer requests.
replyThe answer in getdns reply dict or response dict format. When NULL is given as reply, the request is not answered but all associated state is deleted.
request_idThe identifier that links this response with the received request.
Returns
GETDNS_RETURN_GOOD on success or an error code on failure. On fatal failure (no retry strategy possible) the user still needs to cancel the request by recalling getdns_reply() but with NULL as response, to clean up state.