context.c revision 3489d64bde03af5c7950661b083b530bd285ec27
/*
* Copyright (C) 2000, 2001 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 INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM 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.40 2001/07/19 04:57:46 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
/*
* Define a Macro to make a socket nonblocking
*/
#ifndef MAKE_NONBLOCKING
do {\
if (retval != -1) {\
retval |= O_NONBLOCK; \
}\
} while (0)
#endif
const char *lwres_resolv_conf = LWRES_RESOLV_CONF;
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) {
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);
}