* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: name.h,v 1.76 2000/07/27 09:48:04 tale Exp $ */
+/* $Id: name.h,v 1.77 2000/07/31 23:09:47 tale Exp $ */
#ifndef DNS_NAME_H
#define DNS_NAME_H 1
/*
* Convert 'name' into text format, storing the result in 'target'.
*
- * If 'omit_final_dot' is true, then the final '.' in absolute
- * names other than the root name will be omitted.
+ * Notes:
+ * If 'omit_final_dot' is true, then the final '.' in absolute
+ * names other than the root name will be omitted.
+ *
+ * If dns_name_countlabels == 0, the name will be "@", representing the
+ * current origin as described by RFC 1035.
+ *
+ * The name is not NUL terminated.
*
* Requires:
*
*
* 'target' is a valid buffer.
*
- * dns_name_countlabels(name) > 0
- *
* if dns_name_isabsolute == FALSE, then omit_final_dot == FALSE
*
* Ensures:
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: name.c,v 1.98 2000/07/27 09:46:16 tale Exp $ */
+/* $Id: name.c,v 1.99 2000/07/31 23:09:49 tale Exp $ */
#include <config.h>
* wire format.
*/
REQUIRE(VALID_NAME(name));
- REQUIRE(name->labels > 0);
ndata = name->ndata;
nlen = name->length;
trem = tlen;
- /* Special handling for root label. */
- if (nlen == 1 && labels == 1 && *ndata == 0) {
+ if (labels == 0 && nlen == 0) {
+ /*
+ * Special handling for an empty name.
+ */
+ if (trem == 0)
+ return (ISC_R_NOSPACE);
+
+ /*
+ * The names of these booleans are misleading in this case.
+ * This empty name is not necessarily from the root node of
+ * the DNS root zone, nor is a final dot going to be included.
+ * They need to be set this way, though, to keep the "@"
+ * from being trounced.
+ */
saw_root = ISC_TRUE;
- labels = 0;
+ omit_final_dot = ISC_FALSE;
+ *tdata++ = '@';
+ trem--;
+
+ /*
+ * Skip the while() loop.
+ */
nlen = 0;
+ } else if (nlen == 1 && labels == 1 && *ndata == '\0') {
+ /*
+ * Special handling for the root label.
+ */
if (trem == 0)
return (ISC_R_NOSPACE);
+
+ saw_root = ISC_TRUE;
+ omit_final_dot = ISC_FALSE;
*tdata++ = '.';
trem--;
- omit_final_dot = ISC_FALSE;
+
+ /*
+ * Skip the while() loop.
+ */
+ nlen = 0;
}
-
+
while (labels > 0 && nlen > 0 && trem > 0) {
labels--;
count = *ndata++;
} else {
FATAL_ERROR(__FILE__, __LINE__,
"Unexpected label type %02x", count);
- /* Does not return. */
+ /* NOTREACHED */
}
/*
if (nlen != 0 && trem == 0)
return (ISC_R_NOSPACE);
- INSIST(nlen == 0);
+
if (!saw_root || omit_final_dot)
trem++;
} else
snprintf(cp, size, "<unknown>");
}
-