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

📄 name.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 5 页
字号:
			count2 = *label2++;			if (count2 == 0)				count2 = 256;			if (count1 < count2) {				cdiff = -1;				count = count1;			} else {				count = count2;				if (count1 > count2)					cdiff = 1;				else					cdiff = 0;			}			/* Yes, this loop is really slow! */			for (n = 0; n < count; n++) {				b1 = get_bit(label1, n);				b2 = get_bit(label2, n);				if (b1 < b2) {					*orderp = -1;					goto done;				} else if (b1 > b2) {					*orderp = 1;					goto done;				}				if (nbits == 0)					nlabels++;				nbits++;			}			if (cdiff != 0) {				/*				 * If we're here, then we have two bitstrings				 * of differing length.				 *				 * If the name with the shorter bitstring				 * has any labels, then it must be greater				 * than the longer bitstring.  This is a bit				 * counterintuitive.  If the name with the				 * shorter bitstring has any more labels, then				 * the next label must be an ordinary label.				 * It can't be a bitstring label because if it				 * were, then there would be room for it in				 * the current bitstring label (since all				 * bitstrings are canonicalized).  Since				 * there's at least one more bit in the				 * name with the longer bitstring, and since				 * a bitlabel sorts before any ordinary label,				 * the name with the longer bitstring must				 * be lexically before the one with the shorter				 * bitstring.				 *				 * On the other hand, if there are no more				 * labels in the name with the shorter				 * bitstring, then that name contains the				 * other name.				 */				namereln = dns_namereln_commonancestor;				if (cdiff < 0) {					if (l1 > 0)						*orderp = 1;					else {						*orderp = -1;						namereln =							dns_namereln_contains;					}				} else {					if (l2 > 0)						*orderp = -1;					else {						*orderp = 1;						namereln =							dns_namereln_subdomain;					}				}				goto done;			}			nbits = 0;		}	}	*orderp = ldiff;	if (ldiff < 0)		namereln = dns_namereln_contains;	else if (ldiff > 0)		namereln = dns_namereln_subdomain;	else		namereln = dns_namereln_equal; done:	*nlabelsp = nlabels;	*nbitsp = nbits;	if (nlabels > 0 && namereln == dns_namereln_none)		namereln = dns_namereln_commonancestor;	return (namereln);}intdns_name_compare(const dns_name_t *name1, const dns_name_t *name2) {	int order;	unsigned int nlabels, nbits;	/*	 * Determine the relative ordering under the DNSSEC order relation of	 * 'name1' and 'name2'.	 *	 * Note: It makes no sense for one of the names to be relative and the	 * other absolute.  If both names are relative, then to be meaningfully	 * compared the caller must ensure that they are both relative to the	 * same domain.	 */	(void)dns_name_fullcompare(name1, name2, &order, &nlabels, &nbits);	return (order);}isc_boolean_tdns_name_equal(const dns_name_t *name1, const dns_name_t *name2) {	unsigned int l, count;	unsigned char c;	unsigned char *label1, *label2;	/*	 * Are 'name1' and 'name2' equal?	 *	 * Note: It makes no sense for one of the names to be relative and the	 * other absolute.  If both names are relative, then to be meaningfully	 * compared the caller must ensure that they are both relative to the	 * same domain.	 */	REQUIRE(VALID_NAME(name1));	REQUIRE(VALID_NAME(name2));	/*	 * Either name1 is absolute and name2 is absolute, or neither is.	 */	REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) ==		(name2->attributes & DNS_NAMEATTR_ABSOLUTE));	if (name1->length != name2->length)		return (ISC_FALSE);	l = name1->labels;	if (l != name2->labels)		return (ISC_FALSE);	label1 = name1->ndata;	label2 = name2->ndata;	while (l > 0) {		l--;		count = *label1++;		if (count != *label2++)			return (ISC_FALSE);		if (count <= 63) {			while (count > 0) {				count--;				c = maptolower[*label1++];				if (c != maptolower[*label2++])					return (ISC_FALSE);			}		} else {			INSIST(count == DNS_LABELTYPE_BITSTRING);			count = *label1++;			if (count != *label2++)				return (ISC_FALSE);			if (count == 0)				count = 256;			/*			 * Number of bytes.			 */			count = (count + 7) / 8;			while (count > 0) {				count--;				c = *label1++;				if (c != *label2++)					return (ISC_FALSE);			}		}	}	return (ISC_TRUE);}intdns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2) {	unsigned int l1, l2, l, count1, count2, count;	unsigned char c1, c2;	unsigned char *label1, *label2;	/*	 * Compare two absolute names as rdata.	 */	REQUIRE(VALID_NAME(name1));	REQUIRE(name1->labels > 0);	REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) != 0);	REQUIRE(VALID_NAME(name2));	REQUIRE(name2->labels > 0);	REQUIRE((name2->attributes & DNS_NAMEATTR_ABSOLUTE) != 0);	l1 = name1->labels;	l2 = name2->labels;	l = (l1 < l2) ? l1 : l2;	label1 = name1->ndata;	label2 = name2->ndata;	while (l > 0) {		l--;		count1 = *label1++;		count2 = *label2++;		if (count1 <= 63 && count2 <= 63) {			if (count1 != count2)				return ((count1 < count2) ? -1 : 1);			count = count1;			while (count > 0) {				count--;				c1 = maptolower[*label1++];				c2 = maptolower[*label2++];				if (c1 < c2)					return (-1);				else if (c1 > c2)					return (1);			}		} else if (count1 == DNS_LABELTYPE_BITSTRING && count2 <= 63) {			return (1);		} else if (count2 == DNS_LABELTYPE_BITSTRING && count1 <= 63) {			return (-1);		} else {			INSIST(count1 == DNS_LABELTYPE_BITSTRING &&			       count2 == DNS_LABELTYPE_BITSTRING);			count2 = *label2++;			count1 = *label1++;			if (count1 != count2)				return ((count1 < count2) ? -1 : 1);			if (count1 == 0)				count1 = 256;			if (count2 == 0)				count2 = 256;			/* number of bytes */			count = (count1 + 7) / 8;			while (count > 0) {				count--;				c1 = *label1++;				c2 = *label2++;				if (c1 != c2)					return ((c1 < c2) ? -1 : 1);			}		}	}	/*	 * If one name had more labels than the other, their common	 * prefix must have been different because the shorter name	 * ended with the root label and the longer one can't have	 * a root label in the middle of it.  Therefore, if we get	 * to this point, the lengths must be equal.	 */	INSIST(l1 == l2);	return (0);}isc_boolean_tdns_name_issubdomain(const dns_name_t *name1, const dns_name_t *name2) {	int order;	unsigned int nlabels, nbits;	dns_namereln_t namereln;	/*	 * Is 'name1' a subdomain of 'name2'?	 *	 * Note: It makes no sense for one of the names to be relative and the	 * other absolute.  If both names are relative, then to be meaningfully	 * compared the caller must ensure that they are both relative to the	 * same domain.	 */	namereln = dns_name_fullcompare(name1, name2, &order, &nlabels,					&nbits);	if (namereln == dns_namereln_subdomain ||	    namereln == dns_namereln_equal)		return (ISC_TRUE);	return (ISC_FALSE);}isc_boolean_tdns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname) {	int order;	unsigned int nlabels, nbits, labels;	dns_name_t tname;	REQUIRE(VALID_NAME(name));	REQUIRE(name->labels > 0);	REQUIRE(VALID_NAME(wname));	labels = wname->labels;	REQUIRE(labels > 0);	REQUIRE(dns_name_iswildcard(wname));	DNS_NAME_INIT(&tname, NULL);	dns_name_getlabelsequence(wname, 1, labels - 1, &tname);	if (dns_name_fullcompare(name, &tname, &order, &nlabels, &nbits) ==	    dns_namereln_subdomain)		return (ISC_TRUE);	return (ISC_FALSE);}unsigned intdns_name_depth(const dns_name_t *name) {	unsigned int depth, count, nrem, n;	unsigned char *ndata;	/*	 * The depth of 'name'.	 */	REQUIRE(VALID_NAME(name));	if (name->labels == 0)		return (0);	depth = 0;	ndata = name->ndata;	nrem = name->length;	while (nrem > 0) {		count = *ndata++;		nrem--;		if (count > 63) {			INSIST(count == DNS_LABELTYPE_BITSTRING);			INSIST(nrem != 0);			n = *ndata++;			nrem--;			if (n == 0)				n = 256;			depth += n;			count = n / 8;			if (n % 8 != 0)				count++;		} else {			depth++;			if (count == 0)				break;		}		INSIST(nrem >= count);		nrem -= count;		ndata += count;	}	return (depth);}unsigned intdns_name_countlabels(const dns_name_t *name) {	/*	 * How many labels does 'name' have?	 */	REQUIRE(VALID_NAME(name));	ENSURE(name->labels <= 128);	return (name->labels);}voiddns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label) {	unsigned char *offsets;	dns_offsets_t odata;	/*	 * Make 'label' refer to the 'n'th least significant label of 'name'.	 */	REQUIRE(VALID_NAME(name));	REQUIRE(name->labels > 0);	REQUIRE(n < name->labels);	REQUIRE(label != NULL);	SETUP_OFFSETS(name, offsets, odata);	label->base = &name->ndata[offsets[n]];	if (n == name->labels - 1)		label->length = name->length - offsets[n];	else		label->length = offsets[n + 1] - offsets[n];}voiddns_name_getlabelsequence(const dns_name_t *source,			  unsigned int first, unsigned int n,			  dns_name_t *target){	unsigned char *offsets;	dns_offsets_t odata;	unsigned int firstoffset, endoffset;	/*	 * Make 'target' refer to the 'n' labels including and following	 * 'first' in 'source'.	 */	REQUIRE(VALID_NAME(source));	REQUIRE(VALID_NAME(target));	REQUIRE(first <= source->labels);	REQUIRE(first + n <= source->labels);	REQUIRE(BINDABLE(target));	SETUP_OFFSETS(source, offsets, odata);	if (first == source->labels)		firstoffset = source->length;	else		firstoffset = offsets[first];	if (first + n == source->labels)		endoffset = source->length;	else		endoffset = offsets[first + n];	target->ndata = &source->ndata[firstoffset];	target->length = endoffset - firstoffset;		if (first + n == source->labels && n > 0 &&	    (source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)		target->attributes |= DNS_NAMEATTR_ABSOLUTE;	else		target->attributes &= ~DNS_NAMEATTR_ABSOLUTE;	target->labels = n;	/*	 * If source and target are the same, and we're making target	 * a prefix of source, the offsets table is correct already	 * so we don't need to call set_offsets().	 */	if (target->offsets != NULL &&	    (target != source || first != 0))		set_offsets(target, target->offsets, NULL);}voiddns_name_clone(dns_name_t *source, dns_name_t *target) {	/*	 * Make 'target' refer to the same name as 'source'.	 */	REQUIRE(VALID_NAME(source));	REQUIRE(VALID_NAME(target));	REQUIRE(BINDABLE(target));	target->ndata = source->ndata;	target->length = source->length;	target->labels = source->labels;	target->attributes = source->attributes &		(unsigned int)~(DNS_NAMEATTR_READONLY | DNS_NAMEATTR_DYNAMIC |				DNS_NAMEATTR_DYNOFFSETS);	if (target->offsets != NULL && source->labels > 0) {		if (source->offsets != NULL)			memcpy(target->offsets, source->offsets,			       source->labels);		else			set_offsets(target, target->offsets, NULL);	}}voiddns_name_fromregion(dns_name_t *name, isc_region_t *r) {	unsigned char *offsets;	dns_offsets_t odata;	unsigned int len;	isc_region_t r2;	/*	 * Make 'name' refer to region 'r'.	 */	REQUIRE(VALID_NAME(name));	REQUIRE(r != NULL);	REQUIRE(BINDABLE(name));	INIT_OFFSETS(name, offsets, odata);	if (name->buffer != NULL) {		isc_buffer_clear(name->buffer);		isc_buffer_availableregion(name->buffer, &r2);		len = (r->length < r2.length) ? r->length : r2.length;		if (len > DNS_NAME_MAXWIRE)			len = DNS_NAME_MAXWIRE;		memcpy(r2.base, r->base, len);		name->ndata = r2.base;		name->length = len;	} else {		name->ndata = r->base;		name->length = (r->length <= DNS_NAME_MAXWIRE) ? 			r->length : DNS_NAME_MAXWIRE;	}	if (r->length > 0)		set_offsets(name, offsets, name);	else {		name->labels = 0;		name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;	}	if (name->buffer != NULL)		isc_buffer_add(name->buffer, name->length);}voiddns_name_toregion(dns_name_t *name, isc_region_t *r) {	/*	 * Make 'r' refer to 'name'.	 */	REQUIRE(VALID_NAME(name));	REQUIRE(r != NULL);	DNS_NAME_TOREGION(name, r);}isc_result_tdns_name_fromtext(dns_name_t *name, isc_buffer_t *source,		  dns_name_t *origin, isc_boolean_t downcase,		  isc_buffer_t *target){	unsigned char *ndata, *label;	char *tdata;	char c;	ft_state state, kind;	unsigned int value, count, tbcount, bitlength, maxlength;	unsigned int n1, n2, vlen, tlen, nrem, nused, digits, labels, tused;	isc_boolean_t done, saw_bitstring;	unsigned char dqchars[4];	unsigned char *offsets;	dns_offsets_t odata;	/*	 * Convert the textual representation of a DNS name at source	 * into uncompressed wire form stored in target.	 *	 * Notes:	 *	Relative domain names will have 'origin' appended to them	 *	unless 'origin' is NULL, in which case relative domain names	 *	will remain relative.	 */	REQUIRE(VALID_NAME(name));	REQUIRE(ISC_BUFFER_VALID(source));	REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||		(target == NULL && ISC_BUFFER_VALID(name->buffer)));	if (target == NULL && name->buffer != NULL) {		target = name->buffer;		isc_buffer_clear(target);	}	REQUIRE(BINDABLE(name));	INIT_OFFSETS(name, offsets, odata);	offsets[0] = 0;	/*	 * Initialize things to make the compiler happy; they're not required.	 */	n1 = 0;	n2 = 0;	vlen = 0;	label = NULL;	digits = 0;	value = 0;

⌨️ 快捷键说明

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