name.c revision fcedc0b54b76f53a9f23bc4b9120e3e8c51328e0
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * Copyright (C) 1998 Internet Software Consortium.
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * Permission to use, copy, modify, and distribute this software for any
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * purpose with or without fee is hereby granted, provided that the above
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence#define VALID_NAME(n) ((n) != NULL && (n)->length > 0)
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrencetypedef enum {
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0c73b546ecfa49b9d1c8fdb9a48d4cd62176124aDavid Lawrence -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
static unsigned char maptolower[] = {
#define CONVERTTOASCII(c)
#define CONVERTFROMASCII(c)
if (bit)
return (dns_labeltype_ordinary);
return (dns_labeltype_bitstring);
unsigned int count;
if (count == 0)
return (count);
if (count == 0)
if (bit == 0)
return (dns_bitlabel_0);
return (dns_bitlabel_1);
return (DNS_TRUE);
return (DNS_FALSE);
l = l1;
l = l2;
ldiff = 0;
l1--;
l2--;
cdiff = 0;
while (count > 0) {
count--;
if (cdiff != 0)
return (cdiff);
if (count2 == 0)
if (count1 == 0)
if (count1 == 0)
if (count2 == 0)
cdiff = 0;
for (n = 0; n < count; n++) {
if (cdiff != 0)
return (cdiff);
return (ldiff);
return (DNS_FALSE);
while (l2 > 0) {
l1--;
l2--;
return (DNS_FALSE);
while (count2 > 0) {
count2--;
return (DNS_FALSE);
return (DNS_FALSE);
if (count1 == 0)
if (count2 == 0)
return (DNS_FALSE);
for (n = 0; n < count2; n++) {
return (DNS_FALSE);
return (DNS_FALSE);
return (DNS_TRUE);
unsigned int first, unsigned int n,
REQUIRE(n > 0);
if (r->length > 0)
char *tdata;
n1 = 0;
n2 = 0;
vlen = 0;
digits = 0;
value = 0;
count = 0;
tbcount = 0;
bitlength = 0;
maxlength = 0;
labels = 0;
c = *tdata++;
tlen--;
switch (state) {
case tw_init:
if (tlen != 0)
return (DNS_R_EMPTYLABEL);
labels++;
*ndata++ = 0;
nrem--;
case tw_start:
ndata++;
nrem--;
count = 0;
case tw_ordinary:
if (count == 0)
return (DNS_R_EMPTYLABEL);
labels++;
if (tlen == 0) {
labels++;
*ndata++ = 0;
nrem--;
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
case tw_initialescape:
ndata++;
nrem--;
case tw_escape:
if (!isdigit(c)) {
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
digits = 0;
value = 0;
case tw_escdecimal:
if (!isdigit(c))
return (DNS_R_BADESCAPE);
digits++;
return (DNS_R_BADESCAPE);
return (DNS_R_LABELTOOLONG);
count++;
if (downcase)
nrem--;
case tw_bitstring:
tbcount = 0;
value = 0;
} else if (isdigit(c)) {
n1 = 0;
n2 = 0;
digits = 0;
goto no_read;
return (DNS_R_BADBITSTRING);
case tw_binary:
goto no_read;
count++;
tbcount++;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
count = 0;
case tw_octal:
goto no_read;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
count = 0;
nrem--;
nrem--;
case tw_hex:
if (!isxdigit(c)) {
goto no_read;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
count = 0;
case tw_dottedquad:
return (DNS_R_BADDOTTEDQUAD);
n1++;
goto no_read;
value = 0;
digits = 0;
case tw_dqdecimal:
if (!isdigit(c)) {
return (DNS_R_BADDOTTEDQUAD);
goto no_read;
digits++;
return (DNS_R_BADDOTTEDQUAD);
case tw_maybeslash:
bitlength = 0;
case tw_finishbitstring:
if (tbcount == 0)
return (DNS_R_BADBITSTRING);
if (count > 0) {
if (n1 != 0)
nrem--;
if (bitlength != 0) {
return (DNS_R_BADBITSTRING);
return (DNS_R_BADBITSTRING);
n1++;
return (DNS_R_BADBITSTRING);
n1++;
return (DNS_R_BADBITSTRING);
if (n1 != 0) {
if ((value &
return (DNS_R_BADBITSTRING);
n1++;
return (DNS_R_NOSPACE);
nrem--;
*label = 0;
labels++;
return (DNS_R_BADBITSTRING);
case tw_bitlength:
if (!isdigit(c)) {
if (bitlength == 0)
return (DNS_R_BADBITSTRING);
goto no_read;
return (DNS_R_BADBITSTRING);
case tw_eatdot:
return (DNS_R_BADBITSTRING);
if (tlen == 0) {
labels++;
*ndata++ = 0;
nrem--;
INSIST(0);
if (!done) {
if (nrem == 0)
return (DNS_R_NOSPACE);
return (DNS_R_UNEXPECTEDEND);
labels++;
return (DNS_R_NOSPACE);
while (n1 > 0) {
c = *label++;
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
n1--;
if (saw_bitstring)
return (DNS_R_SUCCESS);
unsigned char *ndata;
char *tdata;
unsigned int labels;
labels = 0;
nlen = 0;
if (trem == 0)
return (DNS_R_NOSPACE);
trem--;
labels--;
nlen--;
if (count == 0) {
while (count > 0) {
c = *ndata;
return (DNS_R_NOSPACE);
*tdata++ = c;
ndata++;
nlen--;
if (trem == 0)
return (DNS_R_NOSPACE);
*tdata++ = c;
ndata++;
trem--;
nlen--;
return (DNS_R_NOSPACE);
ndata++;
nlen--;
count--;
return (DNS_R_NOSPACE);
if (count == 0)
nlen--;
bytes++;
nibbles++;
return (DNS_R_NOSPACE);
while (nibbles > 0) {
c = *ndata++;
nibbles--;
if (nibbles != 0) {
nibbles--;
return (DNS_R_NOSPACE);
for (i = 0; i < len; i++)
INSIST(0);
if (trem == 0)
return (DNS_R_NOSPACE);
trem--;
return (DNS_R_NOSPACE);
trem++;
return (DNS_R_SUCCESS);
unsigned char *ndata;
offset = 0;
nlabels = 0;
while (nrem > 0) {
nrem--;
offset++;
nrem--;
offset++;
if (count == 0)
count = n;
if (set_labels)
if (currbits == 0)
currindex = 0;
if (headbits == 0)
if (headrem != 0)
if (headrem != 0) {
bit);
currindex++;
headindex++;
headbits++;
count--;
headrem--;
} while (headrem != 0);
tailindex = 0;
tailbits = 0;
while (count > 0) {
currindex++;
tailindex++;
tailbits++;
count--;
newbits = 0;
newindex = 0;
bit);
currindex++;
newindex++;
newbits++;
if (newrem != 0) {
count++;
while (newrem > 0) {
newrem--;
newindex++;
count++;
while (count > 0) {
count--;
count++;
while (count > 0) {
count--;
goto again;