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

📄 ns_print.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * 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. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC 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. */#ifndef lintstatic const char rcsid[] = "$Id: ns_print.c,v 1.3.2.1.4.5 2004/07/28 20:16:45 marka Exp $";#endif/* Import. */#include "port_before.h"#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/nameser.h>#include <arpa/inet.h>#include <isc/assertions.h>#include <isc/dst.h>#include <errno.h>#include <resolv.h>#include <string.h>#include <ctype.h>#include "port_after.h"#ifdef SPRINTF_CHAR# define SPRINTF(x) strlen(sprintf/**/x)#else# define SPRINTF(x) ((size_t)sprintf x)#endif/* Forward. */static size_t	prune_origin(const char *name, const char *origin);static int	charstr(const u_char *rdata, const u_char *edata,			char **buf, size_t *buflen);static int	addname(const u_char *msg, size_t msglen,			const u_char **p, const char *origin,			char **buf, size_t *buflen);static void	addlen(size_t len, char **buf, size_t *buflen);static int	addstr(const char *src, size_t len,		       char **buf, size_t *buflen);static int	addtab(size_t len, size_t target, int spaced,		       char **buf, size_t *buflen);/* Macros. */#define	T(x) \	do { \		if ((x) < 0) \			return (-1); \	} while (0)/* Public. *//* * int * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen) *	Convert an RR to presentation format. * return: *	Number of characters written to buf, or -1 (check errno). */intns_sprintrr(const ns_msg *handle, const ns_rr *rr,	    const char *name_ctx, const char *origin,	    char *buf, size_t buflen){	int n;	n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),			 ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),			 ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),			 name_ctx, origin, buf, buflen);	return (n);}/* * int * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen, *	       name_ctx, origin, buf, buflen) *	Convert the fields of an RR into presentation format. * return: *	Number of characters written to buf, or -1 (check errno). */intns_sprintrrf(const u_char *msg, size_t msglen,	    const char *name, ns_class class, ns_type type,	    u_long ttl, const u_char *rdata, size_t rdlen,	    const char *name_ctx, const char *origin,	    char *buf, size_t buflen){	const char *obuf = buf;	const u_char *edata = rdata + rdlen;	int spaced = 0;	const char *comment;	char tmp[100];	int len, x;	/*	 * Owner.	 */	if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {		T(addstr("\t\t\t", 3, &buf, &buflen));	} else {		len = prune_origin(name, origin);		if (*name == '\0') {			goto root;		} else if (len == 0) {			T(addstr("@\t\t\t", 4, &buf, &buflen));		} else {			T(addstr(name, len, &buf, &buflen));			/* Origin not used or not root, and no trailing dot? */			if (((origin == NULL || origin[0] == '\0') ||			    (origin[0] != '.' && origin[1] != '\0' &&			    name[len] == '\0')) && name[len - 1] != '.') { root:				T(addstr(".", 1, &buf, &buflen));				len++;			}			T(spaced = addtab(len, 24, spaced, &buf, &buflen));		}	}	/*	 * TTL, Class, Type.	 */	T(x = ns_format_ttl(ttl, buf, buflen));	addlen(x, &buf, &buflen);	len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));	T(addstr(tmp, len, &buf, &buflen));	T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));	/*	 * RData.	 */	switch (type) {	case ns_t_a:		if (rdlen != (size_t)NS_INADDRSZ)			goto formerr;		(void) inet_ntop(AF_INET, rdata, buf, buflen);		addlen(strlen(buf), &buf, &buflen);		break;	case ns_t_cname:	case ns_t_mb:	case ns_t_mg:	case ns_t_mr:	case ns_t_ns:	case ns_t_ptr:	case ns_t_dname:		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	case ns_t_hinfo:	case ns_t_isdn:		/* First word. */		T(len = charstr(rdata, edata, &buf, &buflen));		if (len == 0)			goto formerr;		rdata += len;		T(addstr(" ", 1, &buf, &buflen));		    		/* Second word, optional in ISDN records. */		if (type == ns_t_isdn && rdata == edata)			break;		    		T(len = charstr(rdata, edata, &buf, &buflen));		if (len == 0)			goto formerr;		rdata += len;		break;	case ns_t_soa: {		u_long t;		/* Server name. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		T(addstr(" ", 1, &buf, &buflen));		/* Administrator name. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		T(addstr(" (\n", 3, &buf, &buflen));		spaced = 0;		if ((edata - rdata) != 5*NS_INT32SZ)			goto formerr;		/* Serial number. */		t = ns_get32(rdata);  rdata += NS_INT32SZ;		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));		len = SPRINTF((tmp, "%lu", t));		T(addstr(tmp, len, &buf, &buflen));		T(spaced = addtab(len, 16, spaced, &buf, &buflen));		T(addstr("; serial\n", 9, &buf, &buflen));		spaced = 0;		/* Refresh interval. */		t = ns_get32(rdata);  rdata += NS_INT32SZ;		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));		T(len = ns_format_ttl(t, buf, buflen));		addlen(len, &buf, &buflen);		T(spaced = addtab(len, 16, spaced, &buf, &buflen));		T(addstr("; refresh\n", 10, &buf, &buflen));		spaced = 0;		/* Retry interval. */		t = ns_get32(rdata);  rdata += NS_INT32SZ;		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));		T(len = ns_format_ttl(t, buf, buflen));		addlen(len, &buf, &buflen);		T(spaced = addtab(len, 16, spaced, &buf, &buflen));		T(addstr("; retry\n", 8, &buf, &buflen));		spaced = 0;		/* Expiry. */		t = ns_get32(rdata);  rdata += NS_INT32SZ;		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));		T(len = ns_format_ttl(t, buf, buflen));		addlen(len, &buf, &buflen);		T(spaced = addtab(len, 16, spaced, &buf, &buflen));		T(addstr("; expiry\n", 9, &buf, &buflen));		spaced = 0;		/* Minimum TTL. */		t = ns_get32(rdata);  rdata += NS_INT32SZ;		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));		T(len = ns_format_ttl(t, buf, buflen));		addlen(len, &buf, &buflen);		T(addstr(" )", 2, &buf, &buflen));		T(spaced = addtab(len, 16, spaced, &buf, &buflen));		T(addstr("; minimum\n", 10, &buf, &buflen));		break;	    }	case ns_t_mx:	case ns_t_afsdb:	case ns_t_rt: {		u_int t;		if (rdlen < (size_t)NS_INT16SZ)			goto formerr;		/* Priority. */		t = ns_get16(rdata);		rdata += NS_INT16SZ;		len = SPRINTF((tmp, "%u ", t));		T(addstr(tmp, len, &buf, &buflen));		/* Target. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	    }	case ns_t_px: {		u_int t;		if (rdlen < (size_t)NS_INT16SZ)			goto formerr;		/* Priority. */		t = ns_get16(rdata);		rdata += NS_INT16SZ;		len = SPRINTF((tmp, "%u ", t));		T(addstr(tmp, len, &buf, &buflen));		/* Name1. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		T(addstr(" ", 1, &buf, &buflen));		/* Name2. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	    }	case ns_t_x25:		T(len = charstr(rdata, edata, &buf, &buflen));		if (len == 0)			goto formerr;		rdata += len;		break;	case ns_t_txt:		while (rdata < edata) {			T(len = charstr(rdata, edata, &buf, &buflen));			if (len == 0)				goto formerr;			rdata += len;			if (rdata < edata)				T(addstr(" ", 1, &buf, &buflen));		}		break;	case ns_t_nsap: {		char t[2+255*3];		(void) inet_nsap_ntoa(rdlen, rdata, t);		T(addstr(t, strlen(t), &buf, &buflen));		break;	    }	case ns_t_aaaa:		if (rdlen != (size_t)NS_IN6ADDRSZ)			goto formerr;		(void) inet_ntop(AF_INET6, rdata, buf, buflen);		addlen(strlen(buf), &buf, &buflen);		break;	case ns_t_loc: {		char t[255];		/* XXX protocol format checking? */		(void) loc_ntoa(rdata, t);		T(addstr(t, strlen(t), &buf, &buflen));		break;	    }	case ns_t_naptr: {		u_int order, preference;		char t[50];		if (rdlen < 2U*NS_INT16SZ)			goto formerr;		/* Order, Precedence. */		order = ns_get16(rdata);	rdata += NS_INT16SZ;		preference = ns_get16(rdata);	rdata += NS_INT16SZ;		len = SPRINTF((t, "%u %u ", order, preference));		T(addstr(t, len, &buf, &buflen));		/* Flags. */		T(len = charstr(rdata, edata, &buf, &buflen));		if (len == 0)			goto formerr;		rdata += len;		T(addstr(" ", 1, &buf, &buflen));		/* Service. */		T(len = charstr(rdata, edata, &buf, &buflen));		if (len == 0)			goto formerr;		rdata += len;		T(addstr(" ", 1, &buf, &buflen));		/* Regexp. */		T(len = charstr(rdata, edata, &buf, &buflen));		if (len < 0)			return (-1);		if (len == 0)			goto formerr;		rdata += len;		T(addstr(" ", 1, &buf, &buflen));		/* Server. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	    }	case ns_t_srv: {		u_int priority, weight, port;		char t[50];		if (rdlen < 3U*NS_INT16SZ)			goto formerr;		/* Priority, Weight, Port. */		priority = ns_get16(rdata);  rdata += NS_INT16SZ;		weight   = ns_get16(rdata);  rdata += NS_INT16SZ;		port     = ns_get16(rdata);  rdata += NS_INT16SZ;		len = SPRINTF((t, "%u %u %u ", priority, weight, port));		T(addstr(t, len, &buf, &buflen));		/* Server. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	    }	case ns_t_minfo:	case ns_t_rp:		/* Name1. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		T(addstr(" ", 1, &buf, &buflen));		/* Name2. */		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));		break;	case ns_t_wks: {		int n, lcnt;		if (rdlen < 1U + NS_INT32SZ)			goto formerr;		/* Address. */		(void) inet_ntop(AF_INET, rdata, buf, buflen);		addlen(strlen(buf), &buf, &buflen);		rdata += NS_INADDRSZ;		/* Protocol. */		len = SPRINTF((tmp, " %u ( ", *rdata));		T(addstr(tmp, len, &buf, &buflen));		rdata += NS_INT8SZ;		/* Bit map. */		n = 0;		lcnt = 0;		while (rdata < edata) {			u_int c = *rdata++;			do {				if (c & 0200) {					if (lcnt == 0) {						T(addstr("\n\t\t\t\t", 5,							 &buf, &buflen));						lcnt = 10;						spaced = 0;					}					len = SPRINTF((tmp, "%d ", n));					T(addstr(tmp, len, &buf, &buflen));					lcnt--;				}				c <<= 1;			} while (++n & 07);		}		T(addstr(")", 1, &buf, &buflen));		break;	    }	case ns_t_key: {

⌨️ 快捷键说明

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