res_debug.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
/*
* Portions Copyright (c) 1996-1999 by 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka Exp $";
#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 <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[];
#ifdef ORIGINAL_ISC_CODE
#else
#endif /* ORIGINAL_ISC_CODE */
/*
* Print the current options.
*/
void
}
static void
{
static int buflen = 2048;
char *buf;
/*
* Print answer records.
*/
return;
return;
}
rrnum = 0;
for (;;) {
goto cleanup;
}
ns_rr_name(rr),
"; EDNS: version: %u, udp=%u, flags=%04x\n",
} 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.)
*/
const struct res_sym __p_class_syms[] = {
{C_IN, "IN", (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.
*/
const struct res_sym __p_default_section_syms[] = {
{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}
};
const struct res_sym __p_update_section_syms[] = {
{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}
};
const struct res_sym __p_key_syms[] = {
};
const struct res_sym __p_cert_syms[] = {
};
/*
* 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.)
*/
const struct res_sym __p_type_syms[] = {
};
/*
* Names of DNS rcodes.
*/
const struct res_sym __p_rcode_syms[] = {
};
int
if (success)
*success = 1;
}
}
if (success)
*success = 0;
}
const char *
#ifdef SUNW_MT_RESOLVER
char *unname = sym_ntos_unname;
#else
static char unname[20];
#endif /* SUNW_MT_RESOLVER */
if (success)
*success = 1;
}
}
if (success)
*success = 0;
return (unname);
}
const char *
#ifdef SUNW_MT_RESOLVER
char *unname = sym_ntop_unname;
#else
static char unname[20];
#endif /* SUNW_MT_RESOLVER */
if (success)
*success = 1;
}
}
if (success)
*success = 0;
return (unname);
}
/*
* Return a string for the type.
*/
const char *
int success;
const char *result;
static char typebuf[20];
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;
static char classbuf[20];
if (success)
return (result);
return ("BADCLASS");
return (classbuf);
}
/*
* Return a mnemonic for an option
*/
const char *
#ifdef ORIGINAL_ISC_CODE
#else
#endif
#ifdef SUNW_MT_RESOLVER
char *nbuf = p_option_nbuf;
#else
static char nbuf[40];
#endif /* SUNW_MT_RESOLVER */
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";
#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 ORIGINAL_ISC_CODE
/* XXX nonreentrant */
#else
#endif
return (nbuf);
}
}
/*
* Return a mnemonic for a time to live.
*/
const char *
#ifdef SUNW_MT_RESOLVER
char *nbuf = p_time_nbuf;
#else
#endif /* SUNW_MT_RESOLVER */
return (nbuf);
}
/*
* Return a string for the rcode.
*/
const char *
}
/*
* Return a string for a res_sockaddr_union.
*/
const char *
char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"];
switch (u.sin.sin_family) {
case AF_INET:
break;
#ifdef HAS_INET6_STRUCTS
case AF_INET6:
break;
#endif
default:
break;
}
if (size > 0) {
}
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 *
{
#ifdef SUNW_MT_RESOLVER
char *retbuf = precsize_ntoa_retbuf;
#else
#endif /* SUNW_MT_RESOLVER */
unsigned long val;
return (retbuf);
}
static u_int8_t
precsize_aton(const char **strptr) {
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 const char *error = "?";
#ifdef SUNW_MT_RESOLVER
char *tmpbuf = loc_ntoa_tmpbuf;
#else
static char tmpbuf[sizeof
"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
#endif /* SUNW_MT_RESOLVER */
char northsouth, eastwest;
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
dn_count_labels(const char *name) {
/* 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 ORIGINAL_ISC_CODE
#else
#endif
#ifdef SUNW_MT_RESOLVER
char *output = p_secstodate_output;
#else
/* XXX nonreentrant */
#endif /* SUNW_MT_RESOLVER */
#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);
}