1*c8503c07Sguenther /* $OpenBSD: res_debug_syms.c,v 1.2 2015/10/05 02:57:16 guenther Exp $ */
20038de2cSespie
30038de2cSespie /*
40038de2cSespie * ++Copyright++ 1985, 1990, 1993
50038de2cSespie * -
60038de2cSespie * Copyright (c) 1985, 1990, 1993
70038de2cSespie * The Regents of the University of California. All rights reserved.
80038de2cSespie *
90038de2cSespie * Redistribution and use in source and binary forms, with or without
100038de2cSespie * modification, are permitted provided that the following conditions
110038de2cSespie * are met:
120038de2cSespie * 1. Redistributions of source code must retain the above copyright
130038de2cSespie * notice, this list of conditions and the following disclaimer.
140038de2cSespie * 2. Redistributions in binary form must reproduce the above copyright
150038de2cSespie * notice, this list of conditions and the following disclaimer in the
160038de2cSespie * documentation and/or other materials provided with the distribution.
170038de2cSespie * 3. Neither the name of the University nor the names of its contributors
180038de2cSespie * may be used to endorse or promote products derived from this software
190038de2cSespie * without specific prior written permission.
200038de2cSespie *
210038de2cSespie * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
220038de2cSespie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
230038de2cSespie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
240038de2cSespie * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
250038de2cSespie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
260038de2cSespie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
270038de2cSespie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
280038de2cSespie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
290038de2cSespie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
300038de2cSespie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
310038de2cSespie * SUCH DAMAGE.
320038de2cSespie * -
330038de2cSespie * Portions Copyright (c) 1993 by Digital Equipment Corporation.
340038de2cSespie *
350038de2cSespie * Permission to use, copy, modify, and distribute this software for any
360038de2cSespie * purpose with or without fee is hereby granted, provided that the above
370038de2cSespie * copyright notice and this permission notice appear in all copies, and that
380038de2cSespie * the name of Digital Equipment Corporation not be used in advertising or
390038de2cSespie * publicity pertaining to distribution of the document or software without
400038de2cSespie * specific, written prior permission.
410038de2cSespie *
420038de2cSespie * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
430038de2cSespie * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
440038de2cSespie * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
450038de2cSespie * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
460038de2cSespie * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
470038de2cSespie * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
480038de2cSespie * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
490038de2cSespie * SOFTWARE.
500038de2cSespie * -
510038de2cSespie * Portions Copyright (c) 1995 by International Business Machines, Inc.
520038de2cSespie *
530038de2cSespie * International Business Machines, Inc. (hereinafter called IBM) grants
540038de2cSespie * permission under its copyrights to use, copy, modify, and distribute this
550038de2cSespie * Software with or without fee, provided that the above copyright notice and
560038de2cSespie * all paragraphs of this notice appear in all copies, and that the name of IBM
570038de2cSespie * not be used in connection with the marketing of any product incorporating
580038de2cSespie * the Software or modifications thereof, without specific, written prior
590038de2cSespie * permission.
600038de2cSespie *
610038de2cSespie * To the extent it has a right to do so, IBM grants an immunity from suit
620038de2cSespie * under its patents, if any, for the use, sale or manufacture of products to
630038de2cSespie * the extent that such products are used for performing Domain Name System
640038de2cSespie * dynamic updates in TCP/IP networks by means of the Software. No immunity is
650038de2cSespie * granted for any product per se or for any other function of any product.
660038de2cSespie *
670038de2cSespie * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
680038de2cSespie * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
690038de2cSespie * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
700038de2cSespie * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
710038de2cSespie * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
720038de2cSespie * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
730038de2cSespie * --Copyright--
740038de2cSespie */
750038de2cSespie
760038de2cSespie
770038de2cSespie #include <sys/types.h>
780038de2cSespie #include <netinet/in.h>
790038de2cSespie #include <arpa/nameser.h>
800038de2cSespie
810038de2cSespie #include <resolv.h>
820038de2cSespie #include <stdio.h>
830038de2cSespie
840038de2cSespie /*
850038de2cSespie * Names of RR classes and qclasses. Classes and qclasses are the same, except
860038de2cSespie * that C_ANY is a qclass but not a class. (You can ask for records of class
870038de2cSespie * C_ANY, but you can't have any records of that class in the database.)
880038de2cSespie */
890038de2cSespie const struct res_sym __p_class_syms[] = {
900038de2cSespie {C_IN, "IN"},
910038de2cSespie {C_CHAOS, "CHAOS"},
920038de2cSespie {C_HS, "HS"},
930038de2cSespie {C_HS, "HESIOD"},
940038de2cSespie {C_ANY, "ANY"},
950038de2cSespie {C_IN, (char *)0}
960038de2cSespie };
970038de2cSespie
980038de2cSespie /*
990038de2cSespie * Names of RR types and qtypes. Types and qtypes are the same, except
1000038de2cSespie * that T_ANY is a qtype but not a type. (You can ask for records of type
1010038de2cSespie * T_ANY, but you can't have any records of that type in the database.)
1020038de2cSespie */
1030038de2cSespie const struct res_sym __p_type_syms[] = {
1040038de2cSespie {T_A, "A", "address"},
1050038de2cSespie {T_NS, "NS", "name server"},
1060038de2cSespie {T_MD, "MD", "mail destination (deprecated)"},
1070038de2cSespie {T_MF, "MF", "mail forwarder (deprecated)"},
1080038de2cSespie {T_CNAME, "CNAME", "canonical name"},
1090038de2cSespie {T_SOA, "SOA", "start of authority"},
1100038de2cSespie {T_MB, "MB", "mailbox"},
1110038de2cSespie {T_MG, "MG", "mail group member"},
1120038de2cSespie {T_MR, "MR", "mail rename"},
1130038de2cSespie {T_NULL, "NULL", "null"},
1140038de2cSespie {T_WKS, "WKS", "well-known service (deprecated)"},
1150038de2cSespie {T_PTR, "PTR", "domain name pointer"},
1160038de2cSespie {T_HINFO, "HINFO", "host information"},
1170038de2cSespie {T_MINFO, "MINFO", "mailbox information"},
1180038de2cSespie {T_MX, "MX", "mail exchanger"},
1190038de2cSespie {T_TXT, "TXT", "text"},
1200038de2cSespie {T_RP, "RP", "responsible person"},
1210038de2cSespie {T_AFSDB, "AFSDB", "DCE or AFS server"},
1220038de2cSespie {T_X25, "X25", "X25 address"},
1230038de2cSespie {T_ISDN, "ISDN", "ISDN address"},
1240038de2cSespie {T_RT, "RT", "router"},
1250038de2cSespie {T_NSAP, "NSAP", "nsap address"},
1260038de2cSespie {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
1270038de2cSespie {T_SIG, "SIG", "signature"},
1280038de2cSespie {T_KEY, "KEY", "key"},
1290038de2cSespie {T_PX, "PX", "mapping information"},
1300038de2cSespie {T_GPOS, "GPOS", "geographical position (withdrawn)"},
1310038de2cSespie {T_AAAA, "AAAA", "IPv6 address"},
1320038de2cSespie {T_LOC, "LOC", "location"},
1330038de2cSespie {T_NXT, "NXT", "next valid name (unimplemented)"},
1340038de2cSespie {T_EID, "EID", "endpoint identifier (unimplemented)"},
1350038de2cSespie {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
1360038de2cSespie {T_SRV, "SRV", "server selection"},
1370038de2cSespie {T_ATMA, "ATMA", "ATM address (unimplemented)"},
1380038de2cSespie {T_IXFR, "IXFR", "incremental zone transfer"},
1390038de2cSespie {T_AXFR, "AXFR", "zone transfer"},
1400038de2cSespie {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
1410038de2cSespie {T_MAILA, "MAILA", "mail agent (deprecated)"},
1420038de2cSespie {T_UINFO, "UINFO", "user information (nonstandard)"},
1430038de2cSespie {T_UID, "UID", "user ID (nonstandard)"},
1440038de2cSespie {T_GID, "GID", "group ID (nonstandard)"},
1450038de2cSespie {T_NAPTR, "NAPTR", "URN Naming Authority"},
1460038de2cSespie #ifdef ALLOW_T_UNSPEC
1470038de2cSespie {T_UNSPEC, "UNSPEC", "unspecified data (nonstandard)"},
1480038de2cSespie #endif /* ALLOW_T_UNSPEC */
1490038de2cSespie {T_ANY, "ANY", "\"any\""},
1500038de2cSespie {0, NULL, NULL}
1510038de2cSespie };
1520038de2cSespie
1530038de2cSespie const char *
__sym_ntos(const struct res_sym * syms,int number,int * success)1540038de2cSespie __sym_ntos(const struct res_sym *syms, int number, int *success)
1550038de2cSespie {
1560038de2cSespie static char unname[20];
1570038de2cSespie
1580038de2cSespie for (; syms->name != 0; syms++) {
1590038de2cSespie if (number == syms->number) {
1600038de2cSespie if (success)
1610038de2cSespie *success = 1;
1620038de2cSespie return (syms->name);
1630038de2cSespie }
1640038de2cSespie }
1650038de2cSespie
1660038de2cSespie snprintf(unname, sizeof unname, "%d", number);
1670038de2cSespie if (success)
1680038de2cSespie *success = 0;
1690038de2cSespie return (unname);
1700038de2cSespie }
171*c8503c07Sguenther DEF_STRONG(__sym_ntos);
1720038de2cSespie
1730038de2cSespie /*
1740038de2cSespie * Return a string for the type
1750038de2cSespie */
1760038de2cSespie const char *
__p_type(int type)1770038de2cSespie __p_type(int type)
1780038de2cSespie {
1790038de2cSespie return (__sym_ntos (__p_type_syms, type, (int *)0));
1800038de2cSespie }
181*c8503c07Sguenther DEF_STRONG(__p_type);
1820038de2cSespie
1830038de2cSespie /*
1840038de2cSespie * Return a mnemonic for class
1850038de2cSespie */
1860038de2cSespie const char *
__p_class(int class)1870038de2cSespie __p_class(int class)
1880038de2cSespie {
1890038de2cSespie return (__sym_ntos (__p_class_syms, class, (int *)0));
1900038de2cSespie }
191*c8503c07Sguenther DEF_STRONG(__p_class);
1920038de2cSespie
193