context.c revision d364948549856a00bb6d4cd1a9475cb25544cc8e
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * copyright notice and this permission notice appear in all copies.
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt * PERFORMANCE OF THIS SOFTWARE.
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt/* $Id: context.c,v 1.54 2009/09/01 22:52:27 jinmei Exp $ */
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lwres_context_create() creates a #lwres_context_t structure for use in
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lightweight resolver operations. It holds a socket and other data
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt needed for communicating with a resolver daemon. The new
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lwres_context_t is returned through contextp, a pointer to a
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lwres_context_t pointer. This lwres_context_t pointer must initially
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt be NULL, and is modified to point to the newly created
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lwres_context_t.
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt When the lightweight resolver needs to perform dynamic memory
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt allocation, it will call malloc_function to allocate memory and
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt free_function to free it. If malloc_function and free_function are
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt NULL, memory is allocated using malloc and free. It is not
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt permitted to have a NULL malloc_function and a non-NULL free_function
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt or vice versa. arg is passed as the first parameter to the memory
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt allocation functions. If malloc_function and free_function are NULL,
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt arg is unused and should be passed as NULL.
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt Once memory for the structure has been allocated, it is initialized
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt using lwres_conf_init() and returned via *contextp.
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt lwres_context_destroy() destroys a #lwres_context_t, closing its
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt socket. contextp is a pointer to a pointer to the context that is to
#include <config.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "context_p.h"
#include "assert_p.h"
#ifndef LWRES_SOCKADDR_LEN_T
#define LWRES_SOCKADDR_LEN_T unsigned int
#ifndef MAKE_NONBLOCKING
static lwres_result_t
unsigned int flags)
return (LWRES_R_NOMEMORY);
* Init resolv.conf bits.
return (LWRES_R_SUCCESS);
#ifdef WIN32
void *mem;
return (NULL);
return (mem);
static lwres_result_t
int ret;
int domain;
sizeof(lwres_addr_t));
return (LWRES_R_IOERROR);
#ifdef WIN32
InitSockets();
#ifdef WIN32
return (LWRES_R_IOERROR);
if (ret != 0) {
#ifdef WIN32
(void)close(s);
return (LWRES_R_IOERROR);
if (ret < 0) {
#ifdef WIN32
(void)close(s);
return (LWRES_R_IOERROR);
return (LWRES_R_SUCCESS);
int ret;
return (lwresult);
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_IOERROR);
return (LWRES_R_SUCCESS);
int *recvd_len)
int ret;
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_TOOLARGE);
return (LWRES_R_RETRY);
return (LWRES_R_RETRY);
return (LWRES_R_SUCCESS);
int *recvd_len)
int ret2;
return (result);
return (LWRES_R_IOERROR);
if (ret2 < 0)
return (LWRES_R_IOERROR);
if (ret2 == 0)
return (LWRES_R_TIMEOUT);
goto again;
return (result);