* Copyright (c) 1985 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)res_debug.c 5.24 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#if defined(lint) && !defined(DEBUG)
#include <arpa/nameser.h>
extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
extern char *inet_ntoa();
char *_res_resultcodes
[] = {
* Print the contents of a query.
* This is intended to be primarily a debugging routine.
cp
= msg
+ sizeof(HEADER
);
fprintf(file
,"HEADER:\n");
fprintf(file
,"\topcode = %s", _res_opcodes
[hp
->opcode
]);
fprintf(file
,", id = %d", ntohs(hp
->id
));
fprintf(file
,", rcode = %s\n", _res_resultcodes
[hp
->rcode
]);
fprintf(file
,"\theader flags: ");
fprintf(file
,"\n\tqdcount = %d", ntohs(hp
->qdcount
));
fprintf(file
,", ancount = %d", ntohs(hp
->ancount
));
fprintf(file
,", nscount = %d", ntohs(hp
->nscount
));
fprintf(file
,", arcount = %d\n\n", ntohs(hp
->arcount
));
* Print question records.
if (n
= ntohs(hp
->qdcount
)) {
fprintf(file
,"QUESTIONS:\n");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,", type = %s", p_type(_getshort(cp
)));
fprintf(file
,", class = %s\n\n", p_class(_getshort(cp
)));
* Print authoritative answer records
if (n
= ntohs(hp
->ancount
)) {
fprintf(file
,"ANSWERS:\n");
cp
= p_rr(cp
, msg
, file
);
* print name server records
if (n
= ntohs(hp
->nscount
)) {
fprintf(file
,"NAME SERVERS:\n");
cp
= p_rr(cp
, msg
, file
);
* print additional records
if (n
= ntohs(hp
->arcount
)) {
fprintf(file
,"ADDITIONAL RECORDS:\n");
cp
= p_rr(cp
, msg
, file
);
if ((n
= dn_expand(msg
, msg
+ 512, cp
, name
, sizeof(name
))) < 0)
* Print resource record fields in human readable form.
int type
, class, dlen
, n
, c
;
if ((cp
= p_cdname(cp
, msg
, file
)) == NULL
)
return (NULL
); /* compression error */
fprintf(file
,"\n\ttype = %s", p_type(type
= _getshort(cp
)));
fprintf(file
,", class = %s", p_class(class = _getshort(cp
)));
fprintf(file
,", ttl = %s", p_time(cp
));
fprintf(file
,", dlen = %d\n", dlen
= _getshort(cp
));
* Print type specific data, if appropriate
bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
fprintf(file
,"\tinternet address = %s\n",
fprintf(file
,"\tinternet address = %s",
fprintf(file
,", protocol = %d", cp
[4]);
fprintf(file
,", port = %d\n",
fprintf(file
,"\tdomain name = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\tCPU=%.*s\n", n
, cp
);
fprintf(file
,"\tOS=%.*s\n", n
, cp
);
fprintf(file
,"\torigin = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\n\tmail addr = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\n\tserial=%ld", _getlong(cp
));
fprintf(file
,", refresh=%s", p_time(cp
));
fprintf(file
,", retry=%s", p_time(cp
));
fprintf(file
,", expire=%s", p_time(cp
));
fprintf(file
,", min=%s\n", p_time(cp
));
fprintf(file
,"\tpreference = %ld,",_getshort(cp
));
fprintf(file
," name = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\trequests = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\n\terrors = ");
cp
= p_cdname(cp
, msg
, file
);
fprintf(file
,"\t%s\n", cp
);
fprintf(file
,"\t%ld\n", _getlong(cp
));
if (dlen
< sizeof(u_long
) + 1)
bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
fprintf(file
,"\tinternet address = %s, protocol = %d\n\t",
inet_ntoa(inaddr
), *cp
++);
while (cp
< cp1
+ dlen
) {
if (dlen
< NumBytes
) NumBytes
= dlen
;
fprintf(file
, "\tFirst %d bytes of hex data:",
for (i
= 0, DataPtr
= cp
; i
< NumBytes
; i
++, DataPtr
++)
fprintf(file
, " %x", *DataPtr
);
#endif /* ALLOW_T_UNSPEC */
fprintf(file
,"packet size error (%#x != %#x)\n", cp
, cp1
+dlen
);
* Return a string for the type
case T_NS
: /* authoritative server */
case T_MD
: /* mail destination */
case T_MF
: /* mail forwarder */
case T_CNAME
: /* connonical name */
case T_SOA
: /* start of authority zone */
case T_MB
: /* mailbox domain name */
case T_MG
: /* mail group member */
case T_MX
: /* mail routing info */
case T_MR
: /* mail rename name */
case T_NULL
: /* null resource record */
case T_WKS
: /* well known service */
case T_PTR
: /* domain name pointer */
case T_HINFO
: /* host information */
case T_MINFO
: /* mailbox information */
case T_AXFR
: /* zone transfer */
case T_MAILB
: /* mail box */
case T_MAILA
: /* mail address */
case T_ANY
: /* matches any type */
#endif /* ALLOW_T_UNSPEC */
(void)sprintf(nbuf
, "%d", type
);
* Return a mnemonic for class
case C_IN
: /* internet class */
case C_ANY
: /* matches any class */
(void)sprintf(nbuf
, "%d", class);
* Return a mnemonic for a time to live
#define PLURALIZE(x) x, (x == 1) ? "" : "s"
(void)sprintf(p
, "%d day%s", PLURALIZE(value
));
(void)sprintf(p
, "%d hour%s", PLURALIZE(hours
));
(void)sprintf(p
, "%d min%s", PLURALIZE(mins
));
(void)sprintf(p
, "%d sec%s", PLURALIZE(secs
));