#ifndef LIBQMSK_RESOLVE_H
#define LIBQMSK_RESOLVE_H
/**
* @file
*
* DNS resolver interface
*/
#include "error.h"
#include <netdb.h>
/**
* Errors
*/
enum resolve_error_code {
ERR_RESOLVE_NONE,
ERR_RESOLVE_GETADDRINFO, ///< getaddrinfo: <gai_*>
ERR_RESOLVE_GETADDRINFO_EMPTY, ///< getaddrinfo: no results
};
const struct error_list resolve_errors;
/**
* Lookup result state
*/
struct resolve_result {
/** Head of the addrinfo list */
struct addrinfo *list;
/** Current addrinfo item */
struct addrinfo *item;
};
/**
* Resolve the given node/service tuple as a series of addrinfos for the given socktype.
*
* This will never return an empty result.
*
* XXX: still blocking DNS stuff
*
* @param res where to store the result state
* @param node hostname/address to look up
* @param service service/port to look up
* @param socktype a SOCK_* value to return addrinfo's for that socktype
* @param ai_flags optional bitmask of AI_* flags to use
* @param err returned error info
*/
err_t resolve_addr (struct resolve_result *res, const char *node, const char *service, int socktype, int ai_flags, error_t *err);
/**
* Initialize the given result to zero
*/
void resolve_result_init (struct resolve_result *res);
/**
* Get the next address from a result, if any left
*/
struct addrinfo* resolve_result_next (struct resolve_result *res);
/**
* Release the addrinfo resources associated with the given result
*/
void resolve_result_deinit (struct resolve_result *res);
/**
* Returns a pointer to a static buffer containing a string description of the given addrinfo
*/
const char * resolve_addr_text (const struct addrinfo *addr);
#endif