context.c revision dafcb997e390efa4423883dafd100c975c4095d6
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: context.c,v 1.45 2004/03/05 05:12:45 marka Exp $ */
#include <config.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <lwres/platform.h>
#endif
#include "context_p.h"
#include "assert_p.h"
/*
* Some systems define the socket length argument as an int, some as size_t,
* some as socklen_t. The last is what the current POSIX standard mandates.
* This definition is here so it can be portable but easily changed if needed.
*/
#ifndef LWRES_SOCKADDR_LEN_T
#define LWRES_SOCKADDR_LEN_T unsigned int
#endif
/*
* Make a socket nonblocking.
*/
#ifndef MAKE_NONBLOCKING
do { \
if (retval != -1) { \
retval |= O_NONBLOCK; \
} \
} while (0)
#endif
static void *
lwres_malloc(void *, size_t);
static void
lwres_free(void *, void *, size_t);
static lwres_result_t
unsigned int flags)
{
/*
* If we were not given anything special to use, use our own
* functions. These are just wrappers around malloc() and free().
*/
}
return (LWRES_R_NOMEMORY);
/*
* Set up the context.
*/
/*
* Init resolv.conf bits.
*/
return (LWRES_R_SUCCESS);
}
void
}
}
}
void
}
void
}
void *
}
static void *
void *mem;
return (NULL);
return (mem);
}
static void
}
static lwres_result_t
int s;
int ret;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
int domain;
sizeof(lwres_addr_t));
} else {
/* The default is the IPv4 loopback address 127.0.0.1. */
}
} else
return (LWRES_R_IOERROR);
if (s < 0)
return (LWRES_R_IOERROR);
if (ret != 0) {
(void)close(s);
return (LWRES_R_IOERROR);
}
MAKE_NONBLOCKING(s, ret);
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_SUCCESS);
}
int
}
int ret;
if (lwresult != LWRES_R_SUCCESS)
return (lwresult);
}
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_IOERROR);
return (LWRES_R_SUCCESS);
}
int *recvd_len)
{
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
int ret;
} else {
}
/*
* The address of fromlen is cast to void * to shut up compiler
* warnings, namely on systems that have the sixth parameter
* prototyped as a signed int when LWRES_SOCKADDR_LEN_T is
* defined as unsigned.
*/
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_TOOLARGE);
/*
* If we got something other than what we expect, have the caller
* wait for another packet. This can happen if an old result
* comes in, or if someone is sending us random stuff.
*/
return (LWRES_R_RETRY);
} else {
return (LWRES_R_RETRY);
}
return (LWRES_R_SUCCESS);
}
int *recvd_len)
{
int ret2;
/*
* Type of tv_sec is long, so make sure the unsigned long timeout
* does not overflow it.
*/
else
if (result != LWRES_R_SUCCESS)
return (result);
/*
* What happened with select?
*/
if (ret2 < 0)
return (LWRES_R_IOERROR);
if (ret2 == 0)
return (LWRES_R_TIMEOUT);
if (result == LWRES_R_RETRY)
goto again;
return (result);
}