context.c revision 412e5c62115e881cce79921e2467c6c0990a0a8a
/*
* Copyright (C) 2000 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.
*/
#include <config.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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
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.
*/
if ((flags & LWRES_CONTEXT_SERVERMODE) == 0)
/*
* Init resolv.conf bits.
*/
return (LWRES_R_SUCCESS);
}
void
}
}
}
void
}
void
}
void *
}
static void *
void *mem;
(void)arg;
return (NULL);
return (mem);
}
static void
(void)arg;
}
static lwres_result_t
int s;
int ret;
struct sockaddr_in localhost;
if (s < 0)
return (LWRES_R_IOERROR);
if (ret != 0) {
close(s);
return (LWRES_R_IOERROR);
}
return (LWRES_R_SUCCESS);
}
int *recvd_len)
{
int ret;
int ret2;
int flags;
struct sockaddr_in sin;
/*
* Type of tv_sec is long, so make sure the unsigned long timeout
* does not overflow it.
*/
else
if (ret < 0)
return (LWRES_R_IOERROR);
return (LWRES_R_IOERROR);
flags |= O_NONBLOCK;
if (ret < 0)
return (LWRES_R_IOERROR);
flags &= ~O_NONBLOCK;
if (ret < 0)
return (LWRES_R_IOERROR);
/*
* What happened with select?
*/
if (ret2 < 0)
return (LWRES_R_IOERROR);
if (ret2 == 0)
return (LWRES_R_TIMEOUT);
/*
* 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);
/*
* If we got something other than what we expect, re-issue our
* recvfrom() call. This can happen if an old result comes in,
* or if someone is sending us random stuff.
*/
goto again;
return (LWRES_R_SUCCESS);
}