* 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.
static char sccsid
[] = "@(#)debug.c 5.14 (Berkeley) 2/14/89";
*******************************************************************************
* Routines to print out packets received from a name server query.
* Modified version of 4.3BSD BIND res_debug.c 5.6 9/14/85
*******************************************************************************
#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
,", auth. 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
);
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
;
if ((cp
= Print_cdname(cp
, msg
, eom
, file
)) == NULL
) {
fprintf(file
, "(name truncated?)\n");
return (NULL
); /* compression error */
if (_res
.options
& RES_DEBUG2
) {
fprintf(file
,"\n\ttype = %s, class = %s, ttl = %s, dlen = %d",
p_type(type
), p_class(class), p_time(ttl
), dlen
);
* Print type specific data, if appropriate
bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
fprintf(file
,"\tinet address = %s\n",
fprintf(file
,"\tinet 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
,"\tpreference = %d",_getshort(cp
));
fprintf(file
,", mail exchanger = ");
fprintf(file
,"\tmail group member = ");
fprintf(file
,"\tmail box = ");
fprintf(file
,"\tmailbox rename = ");
fprintf(file
,"\tnameserver = ");
fprintf(file
,"\thost name = ");
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=%ld", _getlong(cp
));
fprintf(file
,", refresh=%s", p_time(_getlong(cp
)));
fprintf(file
,", retry=%s\n", p_time(_getlong(cp
)));
fprintf(file
,"\texpire=%s", p_time(_getlong(cp
)));
fprintf(file
,", min=%s\n", p_time(_getlong(cp
)));
fprintf(file
,"\trequests = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\n\terrors = ");
cp
= Print_cdname(cp
, msg
, eom
, file
);
fprintf(file
,"\t%s\n", cp
);
fprintf(file
,"\t%cid %ld\n", type
== T_UID
? 'u' : 'g',
fprintf(file
,"\t%cid of length %ld?\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(n
, NULL
);
fprintf(file
," %s", s
->s_name
);
fprintf(file
, "(type NULL, dlen %d)\n", dlen
);
fprintf(file
,"packet size error (%#x != %#x)\n", cp
, cp1
+dlen
);