/*% * Creates a #lwres_context_t structure for use in * lightweight resolver operations. */ lwres_result_t lwres_context_create(lwres_context_t **contextp, void *arg, lwres_malloc_t malloc_function, lwres_free_t free_function, unsigned int flags) { lwres_context_t *ctx; REQUIRE(contextp != NULL && *contextp == NULL); /* * If we were not given anything special to use, use our own * functions. These are just wrappers around malloc() and free(). */ if (malloc_function == NULL || free_function == NULL) { REQUIRE(malloc_function == NULL); REQUIRE(free_function == NULL); malloc_function = lwres_malloc; free_function = lwres_free; } ctx = malloc_function(arg, sizeof(lwres_context_t)); if (ctx == NULL) return (LWRES_R_NOMEMORY); /* * Set up the context. */ ctx->malloc = malloc_function; ctx->free = free_function; ctx->arg = arg; ctx->sock = -1; ctx->timeout = LWRES_DEFAULT_TIMEOUT; #ifndef WIN32 ctx->serial = time(NULL); /* XXXMLG or BEW */ #else ctx->serial = _time32(NULL); #endif ctx->use_ipv4 = 1; ctx->use_ipv6 = 1; if ((flags & (LWRES_CONTEXT_USEIPV4 | LWRES_CONTEXT_USEIPV6)) == LWRES_CONTEXT_USEIPV6) { ctx->use_ipv4 = 0; } if ((flags & (LWRES_CONTEXT_USEIPV4 | LWRES_CONTEXT_USEIPV6)) == LWRES_CONTEXT_USEIPV4) { ctx->use_ipv6 = 0; } /* * Init resolv.conf bits. */ lwres_conf_init(ctx); *contextp = ctx; return (LWRES_R_SUCCESS); }
int main(int argc, char *argv[]) { lwres_context_t *ctx; const char *file = "/etc/resolv.conf"; int ret; #ifdef USE_ISC_MEM isc_mem_t *mem; isc_result_t result; #endif isc__mem_register(); isc__task_register(); isc__timer_register(); isc__socket_register(); if (argc > 1) { file = argv[1]; } #ifdef USE_ISC_MEM mem = NULL; result = isc_mem_create(0, 0, &mem); INSIST(result == ISC_R_SUCCESS); #endif ctx = NULL; #ifdef USE_ISC_MEM ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0); #else ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0); #endif CHECK(ret, "lwres_context_create"); lwres_conf_init(ctx); if (lwres_conf_parse(ctx, file) == 0) { lwres_conf_print(ctx, stderr); } else { perror("lwres_conf_parse"); } lwres_conf_clear(ctx); lwres_context_destroy(&ctx); #ifdef USE_ISC_MEM isc_mem_stats(mem, stdout); isc_mem_destroy(&mem); #endif return (0); }