⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 一个可用的dns服务器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * ++Copyright++ 1985, 1989 * - * Copyright (c) 1985, 1989 *    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 *    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 * 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. * - * --Copyright-- */#ifndef lintstatic char sccsid[] = "@(#)debug.c	5.26 (Berkeley) 3/21/91";static char rcsid[] = "$Id: debug.c,v 8.10 1996/12/18 04:09:50 vixie Exp $";#endif /* not lint *//* ******************************************************************************* * *  debug.c -- * *	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 * ******************************************************************************* */#ifndef WINNT#include <sys/param.h>#include <sys/socket.h>#include <netinet/in.h>#endif#include <nameser.h>#include <inet.h>#include <resolv.h>#include <netdb.h>#include <stdio.h>#include "res.h"#include "portability.h"/* *  Imported from res_debug.c */extern char *_res_resultcodes[];extern char *_res_opcodes[];char * inet_nsap_ntoa();const char * inet_ntop();#ifdef GUIBOOLEAN doing_nameserver = FALSE;extern void process_nameserver_addition();#endif/* *  Forward references */void Fprint_query(u_char *msg, u_char *eom, int printHeader, FILE *file);/* *  Used to highlight the start of a record when printing it. */#define INDENT "    ->  "/* * Print the contents of a query. * This is intended to be primarily a debugging routine. */voidPrint_query(msg, eom, printHeader)	char *msg, *eom;	int printHeader;{#ifndef GUI    	Fprint_query(msg, eom, printHeader, stdout);#else	Fprint_query(msg, eom, printHeader, outputfile);#endif}voidFprint_query(msg, eom, printHeader,file)	u_char *msg, *eom;	int printHeader;	FILE *file;{	register u_char *cp;	register HEADER *hp;	register int n;	short class;	short type;	/*	 * Print header fields.	 */	hp = (HEADER *)msg;	cp = msg + HFIXEDSZ;	if (printHeader || (_res.options & RES_DEBUG2)) {	    fprintf(file,"    HEADER:\n");	    fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]);	    fprintf(file,", id = %d", ntohs( (u_short) hp->id));	    fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]);	    fprintf(file,"\theader flags: ");	    if (hp->qr) {		    fprintf(file," response");	    } else {		    fprintf(file," query");	    }	    if (hp->aa)		    fprintf(file,", auth. answer");	    if (hp->tc)		    fprintf(file,", truncation");	    if (hp->rd)		    fprintf(file,", want recursion");	    if (hp->ra)		    fprintf(file,", recursion avail.");	    if (hp->unused)		    fprintf(file,", UNUSED-QUERY_BIT");	    if (hp->ad)		    fprintf(file,", authentic data");	    if (hp->cd)		    fprintf(file,", checking disabled");  	    fprintf(file,"\n\tquestions = %d", ntohs( (u_short) hp->qdcount));  	    fprintf(file,",  answers = %d", ntohs( (u_short) hp->ancount));  	    fprintf(file,",  authority records = %d", ntohs( (u_short) hp->nscount));  	    fprintf(file,",  additional = %d\n\n", ntohs( (u_short) hp->arcount));  	}	/*	 * Print question records.	 */ 	if (n = ntohs( (u_short) hp->qdcount)) {		fprintf(file,"    QUESTIONS:\n");		while (--n >= 0) {			fprintf(file,"\t");			cp = Print_cdname(cp, msg, eom, file);			if (cp == NULL)				return;			type = _getshort((u_char*)cp);			cp += INT16SZ;			class = _getshort((u_char*)cp);			cp += INT16SZ;			fprintf(file,", type = %s", p_type(type));			fprintf(file,", class = %s\n", p_class(class));		}	}	/*	 * Print authoritative answer records	 */	if (n = ntohs( (u_short) hp->ancount)) {		fprintf(file,"    ANSWERS:\n");		if (type == T_A && n > MAXADDRS) {			fprintf(file,"Limiting response to MAX Addrs = %d \n",			       MAXADDRS);			n = MAXADDRS;		}		while (--n >= 0) {			fprintf(file, INDENT);			cp = Print_rr(cp, msg, eom, file);			if (cp == NULL)				return;		}	}	/*	 * print name server records	 */	if (n = ntohs( (u_short) hp->nscount)) {		fprintf(file,"    AUTHORITY RECORDS:\n");		while (--n >= 0) {			fprintf(file, INDENT);			cp = Print_rr(cp, msg, eom, file);			if (cp == NULL)				return;		}	}	/*	 * print additional records	 */	if (n = ntohs( (u_short) hp->arcount)) {		fprintf(file,"    ADDITIONAL RECORDS:\n");		while (--n >= 0) {			fprintf(file, INDENT);			cp = Print_rr(cp, msg, eom, file);			if (cp == NULL)				return;		}	}	fprintf(file,"\n------------\n");}u_char *Print_cdname_sub(cp, msg, eom, file, format)	u_char *cp, *msg, *eom;	FILE *file;	int format;{	int n;	char name[MAXDNAME];	n = dn_expand(msg, eom, cp, name, sizeof name);	if (n < 0)		return (NULL);	if (name[0] == '\0') {	    (void) strcpy(name, "(root)");	}	if (format) {	    fprintf(file, "%-30s", name);	} else {	    fputs(name, file);	}#ifdef GUI       /* lgk new code for gui to add to list */       if (doing_nameserver)         process_nameserver_addition(name);#endif		return (cp + n);}u_char *Print_cdname(cp, msg, eom, file)	u_char *cp, *msg, *eom;	FILE *file;{	return (Print_cdname_sub(cp, msg, eom, file, 0));}u_char *Print_cdname2(cp, msg, eom, file)	u_char *cp, *msg, *eom;	FILE *file;{	return (Print_cdname_sub(cp, msg, eom, file, 1));}/* * Print resource record fields in human readable form. */u_char *Print_rr(ocp, msg, eom, file)	u_char *ocp, *msg, *eom;	FILE *file;{	int type, class, dlen, n, c;	u_int32_t rrttl, ttl;	struct in_addr inaddr;	u_char *cp, *cp1, *cp2;	int debug;#ifdef GUI        doing_nameserver = FALSE;#endif	if ((cp = Print_cdname(ocp, msg, eom, file)) == NULL) {		fprintf(file, "(name truncated?)\n");		return (NULL);			/* compression error */	}	type = _getshort((u_char*)cp);	cp += INT16SZ;	class = _getshort((u_char*)cp);	cp += INT16SZ;	rrttl = _getlong((u_char*)cp);	cp += INT32SZ;	dlen = _getshort((u_char*)cp);	cp += INT16SZ;	debug = _res.options & (RES_DEBUG|RES_DEBUG2);	if (debug) {	    if (_res.options & RES_DEBUG2) {		fprintf(file,"\n\ttype = %s, class = %s, dlen = %d",			    p_type(type), p_class(class), dlen);	    }	    if (type == T_SOA) {		fprintf(file,"\n\tttl = %lu (%s)", rrttl, p_time(rrttl));	    }	    (void) putc('\n', file);	} 	cp1 = cp;	/*	 * Print type specific data, if appropriate	 */	switch (type) {	case T_A:		switch (class) {		case C_IN:		case C_HS:			bcopy(cp, (char *)&inaddr, INADDRSZ);			if (dlen == 4) {				fprintf(file,"\tinternet address = %s\n",					inet_ntoa(inaddr));				cp += dlen;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -