nget_answer.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1993,1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Taken from 4.1.3 ypserv resolver code. */
#include <ctype.h>
#include <syslog.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <strings.h>
#include <resolv.h>
#include "nres.h"
#include "prnt.h"
#ifndef NO_DATA
#define NO_DATA NO_ADDRESS
#endif
#ifndef LOG_AUTH
#define LOG_AUTH 0
#endif
typedef union {
} querybuf;
typedef union {
char ac;
} align;
extern int h_errno;
#define MAXALIASES 35
#define MAXADDRS 35
static const char AskedForGot[] =
"gethostby*.getanswer: asked for \"%s\", got \"%s\"";
static char *host_aliases[MAXALIASES];
struct hostent *
{
int anslen;
char *name;
return (ret);
}
}
int
{
char *answer;
int anslen;
/* initialize some hosts variables for getanswer */
if (anslen <= 0) {
return (anslen);
}
case NXDOMAIN:
break;
case SERVFAIL:
break;
case NOERROR:
break;
case FORMERR:
case NOTIMP:
case REFUSED:
default:
break;
}
return (-1);
}
return (anslen);
}
/*
* getanswer() is copied from usr/src/lib/libresolv2/common/gethnamaddr.c.
*/
static struct hostent *
int anslen;
const char *qname;
int qtype;
{
int n;
int haveanswer, had_error;
int toobig = 0;
const char *tname;
switch (qtype) {
case T_A:
case T_AAAA:
break;
case T_PTR:
break;
default:
return (NULL);
}
/*
* find first satisfactory answer
*/
if (qdcount != 1) {
return (NULL);
}
return (NULL);
}
/*
* 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).
*/
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;
had_error++;
continue;
}
cp += n; /* name */
/* XXX - debug? syslog? */
cp += n;
continue; /* XXX - had_error++ ? */
}
continue;
sizeof (tbuf));
had_error++;
continue;
}
cp += n;
/* Store alias. */
bp += n;
buflen -= n;
/* Get canonical name. */
if (n > buflen) {
had_error++;
continue;
}
bp += n;
buflen -= n;
continue;
}
sizeof (tbuf));
had_error++;
continue;
}
cp += n;
/* Get canonical name. */
if (n > buflen) {
had_error++;
continue;
}
bp += n;
buflen -= n;
continue;
}
"gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
cp += n;
continue; /* XXX - had_error++ ? */
}
switch (type) {
case T_PTR:
cp += n;
continue; /* XXX - had_error++ ? */
}
had_error++;
break;
}
/*
* #if MULTI_PTRS_ARE_ALIASES
* cp += n;
* if (!haveanswer)
* host.h_name = bp;
* else if (ap < &host_aliases[MAXALIASES-1])
* *ap++ = bp;
* else
* n = -1;
* if (n != -1) {
* n = strlen(bp) + 1; * for the \0 *
* bp += n;
* buflen -= n;
* }
* break;
* #else
*/
return (&host);
/*
* #endif
*/
case T_A:
case T_AAAA:
cp += n;
continue; /* XXX - had_error++ ? */
}
#ifdef SUNW_REJECT_BOGUS_H_LENGTH
/* Don't accept unexpected address length */
cp += n;
continue;
}
if (!haveanswer) {
#else
if (haveanswer) {
cp += n;
continue;
}
} else {
#endif
int nn;
}
(int)n);
had_error++;
continue;
}
if (!toobig++)
"getanswer: Too many addresses (%d)\n",
MAXADDRS);
cp += n;
continue;
}
bp += n;
buflen -= n;
cp += n;
break;
default:
abort();
}
if (!had_error)
haveanswer++;
}
if (haveanswer) {
if (n > buflen)
goto try_again;
bp += n;
buflen -= n;
}
return (&host);
}
return (NULL);
}