/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1996-2003 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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 (c) 1985
* 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.
*/
/*
* Portions Copyright (c) 1995 by International Business Machines, Inc.
*
* International Business Machines, Inc. (hereinafter called IBM) grants
* permission under its copyrights to use, copy, modify, and distribute this
* Software with or without fee, provided that the above copyright notice and
* all paragraphs of this notice appear in all copies, and that the name of IBM
* not be used in connection with the marketing of any product incorporating
* the Software or modifications thereof, without specific, written prior
* permission.
*
* To the extent it has a right to do so, IBM grants an immunity from suit
* under its patents, if any, for the use, sale or manufacture of products to
* the extent that such products are used for performing Domain Name System
* granted for any product per se or for any other function of any product.
*
* THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
* DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <netdb.h>
#include <resolv.h>
#include <resolv_mt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "port_after.h"
#ifdef SPRINTF_CHAR
#else
#endif
extern const char *_res_opcodes[];
extern const char *_res_sectioncodes[];
#ifndef ORIGINAL_ISC_CODE
#endif /* ORIGINAL_ISC_CODE */
/*%
* Print the current options.
*/
void
}
static void
{
char *buf;
/*
* Print answer records.
*/
return;
return;
}
rrnum = 0;
for (;;) {
goto cleanup;
}
ns_rr_name(rr),
"; EDNS: version: %u, udp=%u, flags=%04x\n",
while (rdatalen >= 4) {
int i;
if (optcode == NS_OPT_NSID) {
if (optlen == 0) {
} else {
for (i = 0; i < optlen; i++)
cp[i]);
for (i = 0; i < optlen; i++)
cp[i] : '.');
}
} else {
if (optlen == 0) {
optcode);
} else {
optcode);
for (i = 0; i < optlen; i++)
cp[i]);
for (i = 0; i < optlen; i++)
cp[i] : '.');
}
}
}
} else {
if (n < 0) {
if (buflen < 131072)
";; memory allocation failure\n");
return;
}
continue;
}
goto cleanup;
}
}
rrnum++;
}
}
/*%
* Print the contents of a query.
* This is intended to be primarily a debugging routine.
*/
void
return;
}
/*
* Print header fields.
*/
";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
}
}
}
/*
* Print the various sections.
*/
}
const u_char *
int n;
return (NULL);
if (name[0] == '\0')
else
return (cp + n);
}
const u_char *
}
/*%
* Return a fully-qualified domain name from a compressed name (with
length supplied). */
const u_char *
int msglen;
char *name;
int namelen;
{
int n, newlen;
return (NULL);
return (NULL);
else
}
return (cp + n);
}
/* XXX: the rest of these functions need to become length-limited, too. */
const u_char *
const u_char *n;
if (n == NULL)
return (NULL);
return (n);
}
/*%
* Names of RR classes and qclasses. Classes and qclasses are the same, except
* that C_ANY is a qclass but not a class. (You can ask for records of class
* C_ANY, but you can't have any records of that class in the database.)
*/
{C_IN, "IN", (char *)0},
{C_CHAOS, "CH", (char *)0},
{C_CHAOS, "CHAOS", (char *)0},
{C_HS, "HS", (char *)0},
{C_HS, "HESIOD", (char *)0},
{C_ANY, "ANY", (char *)0},
{C_NONE, "NONE", (char *)0},
{C_IN, (char *)0, (char *)0}
};
/*%
* Names of message sections.
*/
{ns_s_qd, "QUERY", (char *)0},
{ns_s_an, "ANSWER", (char *)0},
{ns_s_ns, "AUTHORITY", (char *)0},
{ns_s_ar, "ADDITIONAL", (char *)0},
{0, (char *)0, (char *)0}
};
{S_ZONE, "ZONE", (char *)0},
{S_PREREQ, "PREREQUISITE", (char *)0},
{S_UPDATE, "UPDATE", (char *)0},
{S_ADDT, "ADDITIONAL", (char *)0},
{0, (char *)0, (char *)0}
};
};
};
/*%
* Names of RR types and qtypes. Types and qtypes are the same, except
* that T_ANY is a qtype but not a type. (You can ask for records of type
* T_ANY, but you can't have any records of that type in the database.)
*/
};
/*%
* Names of DNS rcodes.
*/
};
int
if (success)
*success = 1;
}
}
if (success)
*success = 0;
}
const char *
if (success)
*success = 1;
}
}
if (success)
*success = 0;
return (unname);
}
const char *
if (success)
*success = 1;
}
}
if (success)
*success = 0;
return (unname);
}
/*%
* Return a string for the type.
*/
const char *
int success;
const char *result;
if (success)
return (result);
return ("BADTYPE");
return (typebuf);
}
/*%
* Return a string for the type.
*/
const char *
switch (opcode) {
case ns_o_update:
break;
default:
break;
}
}
/*%
* Return a mnemonic for class.
*/
const char *
int success;
const char *result;
if (success)
return (result);
return ("BADCLASS");
return (classbuf);
}
/*%
* Return a mnemonic for an option
*/
const char *
switch (option) {
case RES_INIT: return "init";
case RES_DEBUG: return "debug";
case RES_AAONLY: return "aaonly(unimpl)";
case RES_USEVC: return "usevc";
case RES_PRIMARY: return "primry(unimpl)";
case RES_IGNTC: return "igntc";
case RES_RECURSE: return "recurs";
case RES_DEFNAMES: return "defnam";
case RES_STAYOPEN: return "styopn";
case RES_DNSRCH: return "dnsrch";
case RES_INSECURE1: return "insecure1";
case RES_INSECURE2: return "insecure2";
case RES_NOALIASES: return "noaliases";
case RES_USE_INET6: return "inet6";
#ifdef RES_USE_EDNS0 /*%< KAME extension */
case RES_USE_EDNS0: return "edns0";
case RES_NSID: return "nsid";
#endif
#ifdef RES_USE_DNAME
case RES_USE_DNAME: return "dname";
#endif
#ifdef RES_USE_DNSSEC
case RES_USE_DNSSEC: return "dnssec";
#endif
#ifdef RES_NOTLDQUERY
case RES_NOTLDQUERY: return "no-tld-query";
#endif
#ifdef RES_NO_NIBBLE2
case RES_NO_NIBBLE2: return "no-nibble2";
#endif
/* XXX nonreentrant */
return (nbuf);
}
}
/*%
* Return a mnemonic for a time to live.
*/
const char *
return (nbuf);
}
/*%
* Return a string for the rcode.
*/
const char *
}
/*%
* Return a string for a res_sockaddr_union.
*/
const char *
switch (u.sin.sin_family) {
case AF_INET:
break;
#ifdef HAS_INET6_STRUCTS
case AF_INET6:
break;
#endif
default:
break;
}
if (size > 0U) {
}
return (buf);
}
/*%
* routines to convert between on-the-wire RR format and zone file format.
* by 60*60*1000 for that.
*/
1000000,10000000,100000000,1000000000};
static const char *
{
unsigned long val;
return (retbuf);
}
static u_int8_t
const char *cp;
int exponent;
int mantissa;
cp++;
}
}
}
break;
if (mantissa > 9)
mantissa = 9;
return (retval);
}
static u_int32_t
const char *cp;
cp = *latlonstrptr;
cp++;
goto fndhemi;
cp++;
goto fndhemi;
cp++;
}
}
}
}
cp++;
cp++;
switch (*cp) {
case 'N': case 'n':
case 'E': case 'e':
+ secsfrac;
break;
case 'S': case 's':
case 'W': case 'w':
- secsfrac;
break;
default:
retval = 0; /*%< invalid value -- indicates error */
break;
}
switch (*cp) {
case 'N': case 'n':
case 'S': case 's':
break;
case 'E': case 'e':
case 'W': case 'w':
break;
default:
*which = 0; /*%< error */
break;
}
cp++; /*%< skip the hemisphere */
cp++;
cp++;
*latlonstrptr = cp;
return (retval);
}
/*%
* converts a zone file representation in a string to an RDATA on-the-wire
* representation. */
int
const char *ascii;
{
case 3: /*%< 1 + 2, the only valid combination */
} else { /*%< some kind of brokenness */
return (0);
}
break;
default: /*%< we didn't get one of each */
return (0);
}
/* altitude */
if (*cp == '-') {
altsign = -1;
cp++;
}
if (*cp == '+')
cp++;
cp++;
}
}
}
cp++;
cp++;
goto defaults;
cp++;
cp++;
goto defaults;
cp++;
cp++;
goto defaults;
return (16); /*%< size of RR in octets */
}
/*% takes an on-the-wire LOC RR and formats it in a human readable format. */
const char *
char *ascii;
{
static char tmpbuf[sizeof
"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
const char *altsign;
versionval = *cp++;
if (versionval) {
return (ascii);
}
altsign = "-";
} else {
altsign = "";
}
if (latval < 0) {
northsouth = 'S';
} else
northsouth = 'N';
if (longval < 0) {
eastwest = 'W';
} else
eastwest = 'E';
"%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm",
return (ascii);
}
/*% Return the number of DNS hierarchy levels in the name. */
int
/* XXX need to check for \. or use named's nlabels(). */
if (name[i] == '.')
count++;
}
/* don't count initial wildcard */
if (name[0] == '*')
if (count)
count--;
/* don't count the null label for root. */
/* if terminating '.' not found, must adjust */
/* count to include last label */
count++;
return (count);
}
/*%
* Make dates expressed in seconds-since-Jan-1-1970 easy to read.
* SIG records are required to be printed like this, by the Secure DNS RFC.
*/
char *
#ifdef HAVE_TIME_R
#else
#endif
return (output);
}
unsigned long result;
char *endptr;
int success;
if (success)
goto done;
goto done;
errno = 0;
success = 1;
done:
if (successp)
return (result);
}
unsigned long result;
char *endptr;
int success;
if (success)
goto done;
goto done;
errno = 0;
success = 1;
done:
if (successp)
return (result);
}
/*! \file */