src/resolve.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:57:48 +0300
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 173 1a7afcd2dd1a
permissions -rw-r--r--
nexus.c compiles
#ifndef RESOLVE_H
#define RESOLVE_H

/**
 * @file
 *
 * DNS resolver interface
 */
#include "error.h"
#include <netdb.h>

/**
 * 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: 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 /* RESOLVE_H */