/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1985, 1988 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*
*/
#include <ctype.h>
#include <netdb.h>
#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <syslog.h>
/*
* When the name service switch calls libresolv, it doesn't want fallback
*/
static int no_hosts_fallback = 0;
void
__res_set_no_hosts_fallback(void) {
no_hosts_fallback = 1;
}
static int
__res_no_hosts_fallback(void) {
return(no_hosts_fallback);
}
static int stayopen = 0;
static char *any();
#if PACKETSZ > 1024
#else
#endif
typedef union {
} querybuf;
static union {
long al;
char ac;
} align;
int h_errno;
static struct hostent *
int anslen;
int iquery;
{
register int n;
char **hap;
/*
* find first satisfactory answer
*/
if (qdcount) {
if (iquery) {
}
bp += n;
buflen -= n;
} else
while (--qdcount > 0)
} else if (iquery) {
else
}
ap = host_aliases;
hap = h_addr_ptrs;
#endif
haveanswer = 0;
break;
cp += n;
cp += n;
continue;
bp += n;
buflen -= n;
continue;
}
cp += n;
continue;
}
cp += n;
return (&host);
}
#ifdef DEBUG
printf("unexpected answer type %d, size %d\n",
type, n);
#endif
cp += n;
continue;
}
if (haveanswer) {
cp += n;
continue;
}
cp += n;
continue;
}
} else {
if (!iquery) {
}
}
#ifdef DEBUG
printf("size (%d) too big\n", n);
#endif
break;
}
#ifdef SYSV
#else
#endif
bp += n;
cp += n;
haveanswer++;
}
if (haveanswer) {
#else
#endif
return (&host);
} else {
}
}
static struct hostent *_gethtbyname();
struct hostent *
char *name;
{
register char *cp;
int n;
/*
* they end in a dot.
*/
if (!*cp) {
if (*--cp == '.')
break;
}
break;
}
#ifdef DEBUG
printf("res_search failed\n");
#endif
if (errno == ECONNREFUSED)
return (_gethtbyname(name));
else
}
}
static struct hostent *_gethtbyaddr();
static struct hostent *
char *addr;
{
int n;
((unsigned)addr[0] & 0xff));
if (n < 0) {
#ifdef DEBUG
printf("res_query failed\n");
#endif
if (errno == ECONNREFUSED)
}
h_addr_ptrs[0] = (char *)&host_addr;
h_addr_ptrs[1] = (char *)0;
return (hp);
}
/*
* First we get what the PTR record says, but do an extra call
* to gethostbyname() to make sure that someone is not trying to
* spoof us. Hopefully this is not done that often, so good
* performance is not really an issue.
*/
struct hostent *
char *addr;
int len;
int type;
{
/* hang on to what we got as an answer */
/* check to make sure by doing a forward query */
for (a = hp2->h_addr_list; *a; a++)
#ifdef SYSV
#else
#endif
return (hp2);
/*
* we've been spoofed, make sure to log it.
* XXX - syslog needs a security priority level.
*/
}
static void
_sethtent(int f)
{
if (__res_no_hosts_fallback()) return;
else
stayopen |= f;
}
static void
_endhtent(void)
{
if (__res_no_hosts_fallback()) return;
}
}
static struct hostent *
{
char *p;
register char *cp, **q;
if (__res_no_hosts_fallback()) return(NULL);
return (NULL);
return (NULL);
if (*p == '#')
goto again;
goto again;
*cp = '\0';
goto again;
*cp++ = '\0';
/* THIS STUFF IS INTERNET SPECIFIC */
#endif
cp++;
*cp++ = '\0';
cp++;
continue;
}
*q++ = cp;
*cp++ = '\0';
}
*q = NULL;
return (&host);
}
static char *
register char *cp;
char *match;
{
register char *mp, c;
while (c = *cp) {
if (*mp == c)
return (cp);
cp++;
}
return ((char *)0);
}
static struct hostent *
char *name;
{
register struct hostent *p;
register char **cp;
_sethtent(0);
while (p = _gethtent()) {
break;
goto found;
}
_endhtent();
return (p);
}
static struct hostent *
char *addr;
{
register struct hostent *p;
_sethtent(0);
while (p = _gethtent())
#ifdef SYSV
#else
#endif
break;
_endhtent();
return (p);
}