* Copyright (c) 1985,1989 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
* documentation and/or other materials provided with the distribution.
* 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
static char sccsid
[] = "@(#)debug.c 5.26 (Berkeley) 3/21/91";
*******************************************************************************
* Routines to print out packets received from a name server query.
* Modified version of 4.3BSD BIND res_debug.c 5.30 6/27/90
*******************************************************************************
#include <arpa/nameser.h>
* Imported from res_debug.c
extern char *_res_resultcodes
[];
extern char *_res_opcodes
[];
* Used to highlight the start of a record when printing it.
* Print the contents of a query.
* This is intended to be primarily a debugging routine.
Print_query(msg
, eom
, printHeader
)
Fprint_query(msg
, eom
, printHeader
,stdout
);
Fprint_query(msg
, eom
, printHeader
,file
)
cp
= msg
+ sizeof(HEADER
);
if (printHeader
|| (_res
.options
& RES_DEBUG2
)) {
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
," response");
fprintf(file
,", auth. answer");
fprintf(file
,", truncation");
fprintf(file
,", want recursion");
fprintf(file
,", recursion avail.");
fprintf(file
,", primary");
fprintf(file
,"\n\tquestions = %d", ntohs(hp
->qdcount
));
fprintf(file
,", answers = %d", ntohs(hp
->ancount
));
fprintf(file
,", authority records = %d", ntohs(hp
->nscount
));
fprintf(file
,", additional = %d\n\n", ntohs(hp
->arcount
));
* Print question records.
if (n
= ntohs(hp
->qdcount
)) {
fprintf(file
," QUESTIONS:\n");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,", type = %s", p_type(type
));
fprintf(file
,", class = %s\n", p_class(class));
* Print authoritative answer records
if (n
= ntohs(hp
->ancount
)) {
fprintf(file
," ANSWERS:\n");
cp
= Print_rr(cp
, msg
, eom
, file
);
* print name server records
if (n
= ntohs(hp
->nscount
)) {
fprintf(file
," AUTHORITY RECORDS:\n");
cp
= Print_rr(cp
, msg
, eom
, file
);
* print additional records
if (n
= ntohs(hp
->arcount
)) {
fprintf(file
," ADDITIONAL RECORDS:\n");
cp
= Print_rr(cp
, msg
, eom
, file
);
fprintf(file
,"\n------------\n");
Print_cdname_sub(cp
, msg
, eom
, file
, format
)
if ((n
= dn_expand(msg
, eom
, cp
, name
, sizeof(name
))) < 0)
(void) strcpy(name
, "(root)");
fprintf(file
, "%-30s", name
);
fputs((char *)name
, file
);
Print_cdname(cp
, msg
, eom
, file
)
return(Print_cdname_sub(cp
, msg
, eom
, file
, 0));
Print_cdname2(cp
, msg
, eom
, file
)
return(Print_cdname_sub(cp
, msg
, eom
, file
, 1));
* Print resource record fields in human readable form.
Print_rr(cp
, msg
, eom
, file
)
int type
, class, dlen
, n
, c
;
unsigned long rrttl
, ttl
;
if ((cp
= Print_cdname(cp
, msg
, eom
, file
)) == NULL
) {
fprintf(file
, "(name truncated?)\n");
return (NULL
); /* compression error */
debug
= _res
.options
& (RES_DEBUG
|RES_DEBUG2
);
if (_res
.options
& RES_DEBUG2
) {
fprintf(file
,"\n\ttype = %s, class = %s, dlen = %d",
p_type(type
), p_class(class), dlen
);
fprintf(file
,"\n\tttl = %lu (%s)", rrttl
, p_time(rrttl
));
* 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
,"\taddress, class = %d, len = %d\n",
fprintf(file
,"\tcanonical name = ");
fprintf(file
,"\tmail group member = ");
fprintf(file
,"\tmail box = ");
fprintf(file
,"\tmailbox rename = ");
fprintf(file
,"\tpreference = %u",_getshort(cp
));
fprintf(file
,", mail exchanger = ");
fprintf(file
,"\tnameserver = ");
fprintf(file
,"\tname = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\tCPU = %.*s", n
, cp
);
fprintf(file
,"\tOS = %.*s\n", n
, cp
);
fprintf(file
,"\torigin = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\n\tmail addr = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\n\tserial = %lu", _getlong(cp
));
fprintf(file
,"\n\trefresh = %lu (%s)", ttl
, p_time(ttl
));
fprintf(file
,"\n\tretry = %lu (%s)", ttl
, p_time(ttl
));
fprintf(file
,"\n\texpire = %lu (%s)", ttl
, p_time(ttl
));
"\n\tminimum ttl = %lu (%s)\n", ttl
, p_time(ttl
));
fprintf(file
,"\trequests = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\n\terrors = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
(void) fputs("\ttext = \"", file
);
if (n
= (unsigned char) *cp
++) {
for (c
= n
; c
> 0 && cp
< cp2
; c
--)
(void) putc(*cp
++, file
);
(void) putc(*cp
++, file
);
(void) fputs("\"\n", file
);
fprintf(file
,"\tuser info = %s\n", cp
);
fprintf(file
,"\t%cid = %lu\n",type
== T_UID
? 'u' : 'g',
fprintf(file
,"\t%cid of length %d?\n",
type
== T_UID
? 'u' : 'g', dlen
);
struct protoent
*protoPtr
;
if (dlen
< sizeof(u_long
) + 1)
bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
if ((protoPtr
= getprotobynumber(*cp
)) != NULL
) {
fprintf(file
,"\tinet address = %s, protocol = %s\n\t",
inet_ntoa(inaddr
), protoPtr
->p_name
);
fprintf(file
,"\tinet address = %s, protocol = %d\n\t",
while (cp
< cp1
+ dlen
) {
s
= getservbyport((int)htons(n
),
protoPtr
? protoPtr
->p_name
: NULL
);
fprintf(file
," %s", s
->s_name
);
fprintf(file
, "\tNULL (dlen %d)\n", dlen
);
fprintf(file
,"\t??? unknown type %d ???\n", type
);
if (_res
.options
& RES_DEBUG
&& type
!= T_SOA
) {
fprintf(file
,"\tttl = %lu (%s)\n", rrttl
, p_time(rrttl
));
"\n*** Error: record size incorrect (%d != %d)\n\n",