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

📄 res_debug.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 2 页
字号:
	const char *result;	static char classbuf[20];	result = sym_ntos(__p_class_syms, class, &success);	if (success)		return (result);	if (class < 0 || class > 0xfff)		return ("BADCLASS");	sprintf(classbuf, "CLASS%d", class);	return (classbuf);}/* * Return a mnemonic for an option */const char *p_option(u_long option) {	static char nbuf[40];	switch (option) {	case RES_INIT:		return "init";	case RES_DEBUG:		return "debug";	case RES_AAONLY:	return "aaonly(unimpl)";	case RES_USEVC:		return "usevc";	case RES_PRIMARY:	return "primry(unimpl)";	case RES_IGNTC:		return "igntc";	case RES_RECURSE:	return "recurs";	case RES_DEFNAMES:	return "defnam";	case RES_STAYOPEN:	return "styopn";	case RES_DNSRCH:	return "dnsrch";	case RES_INSECURE1:	return "insecure1";	case RES_INSECURE2:	return "insecure2";	case RES_NOALIASES:	return "noaliases";	case RES_USE_INET6:	return "inet6";#ifdef RES_USE_EDNS0	/* KAME extension */	case RES_USE_EDNS0:	return "edns0";#endif#ifdef RES_USE_DNAME	case RES_USE_DNAME:	return "dname";#endif#ifdef RES_USE_DNSSEC	case RES_USE_DNSSEC:	return "dnssec";#endif#ifdef RES_NOTLDQUERY	case RES_NOTLDQUERY:	return "no-tld-query";#endif				/* XXX nonreentrant */	default:		sprintf(nbuf, "?0x%lx?", (u_long)option);				return (nbuf);	}}/* * Return a mnemonic for a time to live. */const char *p_time(u_int32_t value) {	static char nbuf[40];		/* XXX nonreentrant */	if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)		sprintf(nbuf, "%u", value);	return (nbuf);}/* * Return a string for the rcode. */const char *p_rcode(int rcode) {	return (sym_ntos(__p_rcode_syms, rcode, (int *)0));}/* * Return a string for a res_sockaddr_union. */const char *p_sockun(union res_sockaddr_union u, char *buf, size_t size) {	char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"];	switch (u.sin.sin_family) {	case AF_INET:		inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret);		break;#ifdef HAS_INET6_STRUCTS	case AF_INET6:		inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);		break;#endif	default:		sprintf(ret, "[af%d]", u.sin.sin_family);		break;	}	if (size > 0) {		strncpy(buf, ret, size - 1);		buf[size - 1] = '0';	}	return (buf);}/* * routines to convert between on-the-wire RR format and zone file format. * Does not contain conversion to/from decimal degrees; divide or multiply * by 60*60*1000 for that. */static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,				      1000000,10000000,100000000,1000000000};/* takes an XeY precision/size value, returns a string representation. */static const char *precsize_ntoa(prec)	u_int8_t prec;{	static char retbuf[sizeof "90000000.00"];	/* XXX nonreentrant */	unsigned long val;	int mantissa, exponent;	mantissa = (int)((prec >> 4) & 0x0f) % 10;	exponent = (int)((prec >> 0) & 0x0f) % 10;	val = mantissa * poweroften[exponent];	(void) sprintf(retbuf, "%lu.%.2lu", val/100, val%100);	return (retbuf);}/* converts ascii size/precision X * 10**Y(cm) to 0xXY.  moves pointer. */static u_int8_tprecsize_aton(const char **strptr) {	unsigned int mval = 0, cmval = 0;	u_int8_t retval = 0;	const char *cp;	int exponent;	int mantissa;	cp = *strptr;	while (isdigit((unsigned char)*cp))		mval = mval * 10 + (*cp++ - '0');	if (*cp == '.') {		/* centimeters */		cp++;		if (isdigit((unsigned char)*cp)) {			cmval = (*cp++ - '0') * 10;			if (isdigit((unsigned char)*cp)) {				cmval += (*cp++ - '0');			}		}	}	cmval = (mval * 100) + cmval;	for (exponent = 0; exponent < 9; exponent++)		if (cmval < poweroften[exponent+1])			break;	mantissa = cmval / poweroften[exponent];	if (mantissa > 9)		mantissa = 9;	retval = (mantissa << 4) | exponent;	*strptr = cp;	return (retval);}/* converts ascii lat/lon to unsigned encoded 32-bit number.  moves pointer. */static u_int32_tlatlon2ul(const char **latlonstrptr, int *which) {	const char *cp;	u_int32_t retval;	int deg = 0, min = 0, secs = 0, secsfrac = 0;	cp = *latlonstrptr;	while (isdigit((unsigned char)*cp))		deg = deg * 10 + (*cp++ - '0');	while (isspace((unsigned char)*cp))		cp++;	if (!(isdigit((unsigned char)*cp)))		goto fndhemi;	while (isdigit((unsigned char)*cp))		min = min * 10 + (*cp++ - '0');	while (isspace((unsigned char)*cp))		cp++;	if (!(isdigit((unsigned char)*cp)))		goto fndhemi;	while (isdigit((unsigned char)*cp))		secs = secs * 10 + (*cp++ - '0');	if (*cp == '.') {		/* decimal seconds */		cp++;		if (isdigit((unsigned char)*cp)) {			secsfrac = (*cp++ - '0') * 100;			if (isdigit((unsigned char)*cp)) {				secsfrac += (*cp++ - '0') * 10;				if (isdigit((unsigned char)*cp)) {					secsfrac += (*cp++ - '0');				}			}		}	}	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */		cp++;	while (isspace((unsigned char)*cp))		cp++; fndhemi:	switch (*cp) {	case 'N': case 'n':	case 'E': case 'e':		retval = ((unsigned)1<<31)			+ (((((deg * 60) + min) * 60) + secs) * 1000)			+ secsfrac;		break;	case 'S': case 's':	case 'W': case 'w':		retval = ((unsigned)1<<31)			- (((((deg * 60) + min) * 60) + secs) * 1000)			- secsfrac;		break;	default:		retval = 0;	/* invalid value -- indicates error */		break;	}	switch (*cp) {	case 'N': case 'n':	case 'S': case 's':		*which = 1;	/* latitude */		break;	case 'E': case 'e':	case 'W': case 'w':		*which = 2;	/* longitude */		break;	default:		*which = 0;	/* error */		break;	}	cp++;			/* skip the hemisphere */	while (!isspace((unsigned char)*cp))	/* if any trailing garbage */		cp++;	while (isspace((unsigned char)*cp))	/* move to next field */		cp++;	*latlonstrptr = cp;	return (retval);}/* converts a zone file representation in a string to an RDATA on-the-wire * representation. */intloc_aton(ascii, binary)	const char *ascii;	u_char *binary;{	const char *cp, *maxcp;	u_char *bcp;	u_int32_t latit = 0, longit = 0, alt = 0;	u_int32_t lltemp1 = 0, lltemp2 = 0;	int altmeters = 0, altfrac = 0, altsign = 1;	u_int8_t hp = 0x16;	/* default = 1e6 cm = 10000.00m = 10km */	u_int8_t vp = 0x13;	/* default = 1e3 cm = 10.00m */	u_int8_t siz = 0x12;	/* default = 1e2 cm = 1.00m */	int which1 = 0, which2 = 0;	cp = ascii;	maxcp = cp + strlen(ascii);	lltemp1 = latlon2ul(&cp, &which1);	lltemp2 = latlon2ul(&cp, &which2);	switch (which1 + which2) {	case 3:			/* 1 + 2, the only valid combination */		if ((which1 == 1) && (which2 == 2)) { /* normal case */			latit = lltemp1;			longit = lltemp2;		} else if ((which1 == 2) && (which2 == 1)) { /* reversed */			longit = lltemp1;			latit = lltemp2;		} else {	/* some kind of brokenness */			return (0);		}		break;	default:		/* we didn't get one of each */		return (0);	}	/* altitude */	if (*cp == '-') {		altsign = -1;		cp++;	}    	if (*cp == '+')		cp++;	while (isdigit((unsigned char)*cp))		altmeters = altmeters * 10 + (*cp++ - '0');	if (*cp == '.') {		/* decimal meters */		cp++;		if (isdigit((unsigned char)*cp)) {			altfrac = (*cp++ - '0') * 10;			if (isdigit((unsigned char)*cp)) {				altfrac += (*cp++ - '0');			}		}	}	alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));	while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */		cp++;	while (isspace((unsigned char)*cp) && (cp < maxcp))		cp++;	if (cp >= maxcp)		goto defaults;	siz = precsize_aton(&cp);		while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */		cp++;	while (isspace((unsigned char)*cp) && (cp < maxcp))		cp++;	if (cp >= maxcp)		goto defaults;	hp = precsize_aton(&cp);	while (!isspace((unsigned char)*cp) && (cp < maxcp))	/* if trailing garbage or m */		cp++;	while (isspace((unsigned char)*cp) && (cp < maxcp))		cp++;	if (cp >= maxcp)		goto defaults;	vp = precsize_aton(&cp); defaults:	bcp = binary;	*bcp++ = (u_int8_t) 0;	/* version byte */	*bcp++ = siz;	*bcp++ = hp;	*bcp++ = vp;	PUTLONG(latit,bcp);	PUTLONG(longit,bcp);	PUTLONG(alt,bcp);    	return (16);		/* size of RR in octets */}/* takes an on-the-wire LOC RR and formats it in a human readable format. */const char *loc_ntoa(binary, ascii)	const u_char *binary;	char *ascii;{	static const char *error = "?";	static char tmpbuf[sizeof"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];	const u_char *cp = binary;	int latdeg, latmin, latsec, latsecfrac;	int longdeg, longmin, longsec, longsecfrac;	char northsouth, eastwest;	const char *altsign;	int altmeters, altfrac;	const u_int32_t referencealt = 100000 * 100;	int32_t latval, longval, altval;	u_int32_t templ;	u_int8_t sizeval, hpval, vpval, versionval;    	char *sizestr, *hpstr, *vpstr;	versionval = *cp++;	if (ascii == NULL)		ascii = tmpbuf;	if (versionval) {		(void) sprintf(ascii, "; error: unknown LOC RR version");		return (ascii);	}	sizeval = *cp++;	hpval = *cp++;	vpval = *cp++;	GETLONG(templ, cp);	latval = (templ - ((unsigned)1<<31));	GETLONG(templ, cp);	longval = (templ - ((unsigned)1<<31));	GETLONG(templ, cp);	if (templ < referencealt) { /* below WGS 84 spheroid */		altval = referencealt - templ;		altsign = "-";	} else {		altval = templ - referencealt;		altsign = "";	}	if (latval < 0) {		northsouth = 'S';		latval = -latval;	} else		northsouth = 'N';	latsecfrac = latval % 1000;	latval = latval / 1000;	latsec = latval % 60;	latval = latval / 60;	latmin = latval % 60;	latval = latval / 60;	latdeg = latval;	if (longval < 0) {		eastwest = 'W';		longval = -longval;	} else		eastwest = 'E';	longsecfrac = longval % 1000;	longval = longval / 1000;	longsec = longval % 60;	longval = longval / 60;	longmin = longval % 60;	longval = longval / 60;	longdeg = longval;	altfrac = altval % 100;	altmeters = (altval / 100);	sizestr = strdup(precsize_ntoa(sizeval));	hpstr = strdup(precsize_ntoa(hpval));	vpstr = strdup(precsize_ntoa(vpval));	sprintf(ascii,	    "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm",		latdeg, latmin, latsec, latsecfrac, northsouth,		longdeg, longmin, longsec, longsecfrac, eastwest,		altsign, altmeters, altfrac,		(sizestr != NULL) ? sizestr : error,		(hpstr != NULL) ? hpstr : error,		(vpstr != NULL) ? vpstr : error);	if (sizestr != NULL)		free(sizestr);	if (hpstr != NULL)		free(hpstr);	if (vpstr != NULL)		free(vpstr);	return (ascii);}/* Return the number of DNS hierarchy levels in the name. */intdn_count_labels(const char *name) {	int i, len, count;	len = strlen(name);	for (i = 0, count = 0; i < len; i++) {		/* XXX need to check for \. or use named's nlabels(). */		if (name[i] == '.')			count++;	}	/* don't count initial wildcard */	if (name[0] == '*')		if (count)			count--;	/* don't count the null label for root. */	/* if terminating '.' not found, must adjust */	/* count to include last label */	if (len > 0 && name[len-1] != '.')		count++;	return (count);}/*  * Make dates expressed in seconds-since-Jan-1-1970 easy to read.   * SIG records are required to be printed like this, by the Secure DNS RFC. */char *p_secstodate (u_long secs) {	/* XXX nonreentrant */	static char output[15];		/* YYYYMMDDHHMMSS and null */	time_t clock = secs;	struct tm *time;	#ifdef HAVE_TIME_R	gmtime_r(&clock, &time);#else	time = gmtime(&clock);#endif	time->tm_year += 1900;	time->tm_mon += 1;	sprintf(output, "%04d%02d%02d%02d%02d%02d",		time->tm_year, time->tm_mon, time->tm_mday,		time->tm_hour, time->tm_min, time->tm_sec);	return (output);}u_int16_tres_nametoclass(const char *buf, int *successp) {	unsigned long result;	char *endptr;	int success;	result = sym_ston(__p_class_syms, buf, &success);	if (success)		goto done;	if (strncasecmp(buf, "CLASS", 5) != 0 ||	    !isdigit((unsigned char)buf[5]))		goto done;	errno = 0;	result = strtoul(buf + 5, &endptr, 10);	if (errno == 0 && *endptr == '\0' && result <= 0xffff)		success = 1; done:	if (successp)		*successp = success;	return (result);}u_int16_tres_nametotype(const char *buf, int *successp) {	unsigned long result;	char *endptr;	int success;	result = sym_ston(__p_type_syms, buf, &success);	if (success)		goto done;	if (strncasecmp(buf, "type", 4) != 0 ||	    !isdigit((unsigned char)buf[4]))		goto done;	errno = 0;	result = strtoul(buf + 4, &endptr, 10);	if (errno == 0 && *endptr == '\0' && result <= 0xffff)		success = 1; done:	if (successp)		*successp = success;	return (result);}

⌨️ 快捷键说明

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