/*
* ++Copyright++ 1985, 1988, 1993
* -
* Copyright (c) 1985, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* 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, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION 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.
* -
* --Copyright--
*/
/*
* Portions copyright (c) 1999, 2000
* Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*
* This product includes software developed by Intel Corporation and
* its contributors.
*
* 4. Neither the name of Intel Corporation or its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <resolv.h>
#include <ctype.h>
#include <errno.h>
#ifdef _ORG_FREEBSD_
#include <syslog.h>
#else
#include <stdlib.h>
#endif
#include "res_config.h"
#include "Socklib_internals.h"
static const char AskedForGot[] =
"gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
#ifdef RESOLVSORT
static void addrsort(char **, int);
#endif
#if PACKETSZ > 1024
#else
#endif
typedef union {
} querybuf;
typedef union {
char ac;
} align;
extern int h_errno;
int _dns_ttl_;
#ifdef DEBUG_RES
static void
{
}
}
#else
#endif
#define BOUNDED_INCR(x) \
do { \
cp += x; \
h_errno = NO_RECOVERY; \
return (NULL); \
} \
} while (0)
do { \
h_errno = NO_RECOVERY; \
return (NULL); \
} \
} while (0)
static struct hostent *
{
register int n;
int toobig = 0;
const char *tname;
int (*name_ok)(const char *);
switch (qtype) {
case T_A:
case T_AAAA:
break;
case T_PTR:
break;
default:
return (NULL); /* XXX should be abort(); */
}
/*
* find first satisfactory answer
*/
if (qdcount != 1) {
return (NULL);
}
return (NULL);
}
BOUNDED_INCR(n + QFIXEDSZ);
/* res_send() has already verified that the query name is the
* same as the one we sent; this just gets the expanded name
* (i.e., with the succeeding search-domain tacked on).
*/
if (n >= MAXHOSTNAMELEN) {
return (NULL);
}
bp += n;
buflen -= n;
/* The qname can be abbreviated, but h_name is now absolute. */
}
ap = host_aliases;
hap = h_addr_ptrs;
haveanswer = 0;
had_error = 0;
_dns_ttl_ = -1;
had_error++;
continue;
}
cp += n; /* name */
BOUNDS_CHECK(cp, n);
/* XXX - debug? syslog? */
cp += n;
continue; /* XXX - had_error++ ? */
}
continue;
had_error++;
continue;
}
cp += n;
return (NULL);
}
/* Store alias. */
if (n >= MAXHOSTNAMELEN) {
had_error++;
continue;
}
bp += n;
buflen -= n;
/* Get canonical name. */
if (n > buflen || n >= MAXHOSTNAMELEN) {
had_error++;
continue;
}
bp += n;
buflen -= n;
continue;
}
had_error++;
continue;
}
cp += n;
return (NULL);
}
/* Get canonical name. */
if (n > buflen || n >= MAXHOSTNAMELEN) {
had_error++;
continue;
}
bp += n;
buflen -= n;
continue;
}
#ifdef _ORG_FREEBSD_
"gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
#endif
cp += n;
continue; /* XXX - had_error++ ? */
}
switch (type) {
case T_PTR:
#ifdef _ORG_FREEBSD_
#endif
cp += n;
continue; /* XXX - had_error++ ? */
}
had_error++;
break;
}
cp += n;
return (NULL);
}
if (!haveanswer)
else
n = -1;
if (n != -1) {
if (n >= MAXHOSTNAMELEN) {
had_error++;
break;
}
bp += n;
buflen -= n;
}
break;
#else
if (n >= MAXHOSTNAMELEN) {
had_error++;
break;
}
bp += n;
buflen -= n;
}
return (&host);
#endif
case T_A:
case T_AAAA:
#ifdef _ORG_FREEBSD_
#endif
cp += n;
continue; /* XXX - had_error++ ? */
}
cp += n;
continue;
}
if (!haveanswer) {
register int nn;
}
dprintf("size (%d) too big\n", n);
had_error++;
continue;
}
if (!toobig++)
dprintf("Too many addresses (%d)\n",
MAXADDRS);
cp += n;
continue;
}
bp += n;
buflen -= n;
cp += n;
return (NULL);
}
break;
default:
return (NULL);
/* BIND has abort() here, too risky on bad data */
}
if (!had_error)
haveanswer++;
}
if (haveanswer) {
# if defined(RESOLVSORT)
/*
* Note: we sort even if host can take only one address
* in its return structures - should give it the "best"
* address in that case, not some random one
*/
# endif /*RESOLVSORT*/
if (n > buflen || n >= MAXHOSTNAMELEN)
goto no_recovery;
bp += n;
buflen -= n;
}
return (&host);
}
return (NULL);
}
struct hostent *
{
switch(qtype) {
case T_AAAA:
break;
case T_A:
default:
break;
}
}
struct hostent *
{
register const char *cp;
char *bp;
return (NULL);
}
switch (af) {
case AF_INET:
break;
case AF_INET6:
break;
default:
return (NULL);
}
/*
* if there aren't any dots, it could be a user-level alias.
* this is also done in res_query() since we are not the only
* function that looks up host names.
*/
/*
* they end in a dot.
*/
if (!*cp) {
if (*--cp == '.')
break;
/*
* All-numeric, no dot at the end.
* Fake up a hostent as if we'd actually
* done a lookup.
*/
return (NULL);
}
host_aliases[0] = NULL;
h_addr_ptrs[0] = (char *)host_addr;
return (&host);
}
break;
}
name[0] == ':')
if (!*cp) {
if (*--cp == '.')
break;
/*
* All-IPv6-legal, no dot at the end.
* Fake up a hostent as if we'd actually
* done a lookup.
*/
return (NULL);
}
host_aliases[0] = NULL;
h_addr_ptrs[0] = (char *)host_addr;
return (&host);
}
break;
}
dprintf("res_search failed (%d)\n", n);
return (NULL);
}
}
struct hostent *
{
int n, size;
#ifdef SUNSECURITY
char **haddr;
#endif /*SUNSECURITY*/
return (NULL);
}
/* Unmap. */
}
switch (af) {
case AF_INET:
break;
case AF_INET6:
break;
default:
return (NULL);
}
return (NULL);
}
switch (af) {
case AF_INET:
(uaddr[0] & 0xff));
break;
case AF_INET6:
for (n = IN6ADDRSZ - 1; n >= 0; n--) {
uaddr[n] & 0xf,
}
break;
default:
abort();
}
if (n < 0) {
dprintf("res_query failed (%d)\n", n);
return (NULL);
}
return (NULL); /* h_errno was set by gethostanswer() */
#ifdef SUNSECURITY
/*
* turn off search as the name should be absolute,
* 'localhost' should be matched by defnames
*/
#ifdef _ORG_FREEBSD_
"gethostbyaddr: No A record for %s (verifying [%s])",
#endif
return (NULL);
}
break;
if (!*haddr) {
#ifdef _ORG_FREEBSD_
"gethostbyaddr: A record of %s != PTR record [%s]",
#endif
return (NULL);
}
}
#endif /*SUNSECURITY*/
h_addr_ptrs[0] = (char *)host_addr;
}
return (hp);
}
#ifdef RESOLVSORT
static void
{
short i, j;
char **p;
short needsort = 0;
p = ap;
for (i = 0; i < num; i++, p++) {
break;
aval[i] = j;
needsort = i;
}
if (!needsort)
return;
for (j = needsort - 1; j >= 0; j--) {
char *hp;
i = aval[j];
aval[j+1] = i;
} else
break;
}
needsort++;
}
}
#endif
void
{
return;
if (stayopen)
}
void
{
res_close();
}