#include "ares_private.h"Include dependency graph for ares_expand_name.c:
Go to the source code of this file.
Functions | |
| int | name_length (const unsigned char *encoded, const unsigned char *abuf, int alen) |
| int | ares_expand_name (const unsigned char *encoded, const unsigned char *abuf, int alen, char **s, int *enclen) |
|
||||||||||||||||||||||||
|
Definition at line 52 of file ares_expand_name.c. References ARES_EBADNAME, ARES_ENOMEM, ARES_SUCCESS, INDIR_MASK, len, malloc, and name_length(). Referenced by ares_parse_a_reply(), ares_parse_ptr_reply(), and same_questions().
00054 {
00055 int len, indir = 0;
00056 char *q;
00057 const unsigned char *p;
00058
00059 len = name_length(encoded, abuf, alen);
00060 if (len == -1)
00061 return ARES_EBADNAME;
00062
00063 *s = malloc(len + 1);
00064 if (!*s)
00065 return ARES_ENOMEM;
00066 q = *s;
00067
00068 /* No error-checking necessary; it was all done by name_length(). */
00069 p = encoded;
00070 while (*p)
00071 {
00072 if ((*p & INDIR_MASK) == INDIR_MASK)
00073 {
00074 if (!indir)
00075 {
00076 *enclen = p + 2 - encoded;
00077 indir = 1;
00078 }
00079 p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
00080 }
00081 else
00082 {
00083 len = *p;
00084 p++;
00085 while (len--)
00086 {
00087 if (*p == '.' || *p == '\\')
00088 *q++ = '\\';
00089 *q++ = *p;
00090 p++;
00091 }
00092 *q++ = '.';
00093 }
00094 }
00095 if (!indir)
00096 *enclen = p + 1 - encoded;
00097
00098 /* Nuke the trailing period if we wrote one. */
00099 if (q > *s)
00100 *(q - 1) = 0;
00101
00102 return ARES_SUCCESS;
00103 }
|
Here is the call graph for this function:
|
||||||||||||||||
|
Definition at line 108 of file ares_expand_name.c. References INDIR_MASK. Referenced by ares_expand_name().
00110 {
00111 int n = 0, offset, indir = 0;
00112
00113 /* Allow the caller to pass us abuf + alen and have us check for it. */
00114 if (encoded == abuf + alen)
00115 return -1;
00116
00117 while (*encoded)
00118 {
00119 if ((*encoded & INDIR_MASK) == INDIR_MASK)
00120 {
00121 /* Check the offset and go there. */
00122 if (encoded + 1 >= abuf + alen)
00123 return -1;
00124 offset = (*encoded & ~INDIR_MASK) << 8 | *(encoded + 1);
00125 if (offset >= alen)
00126 return -1;
00127 encoded = abuf + offset;
00128
00129 /* If we've seen more indirects than the message length,
00130 * then there's a loop.
00131 */
00132 if (++indir > alen)
00133 return -1;
00134 }
00135 else
00136 {
00137 offset = *encoded;
00138 if (encoded + offset + 1 >= abuf + alen)
00139 return -1;
00140 encoded++;
00141 while (offset--)
00142 {
00143 n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
00144 encoded++;
00145 }
00146 n++;
00147 }
00148 }
00149
00150 /* If there were any labels at all, then the number of dots is one
00151 * less than the number of labels, so subtract one.
00152 */
00153 return (n) ? n - 1 : n;
00154 }
|
1.3.4