update code
This commit is contained in:
67
dns.c
67
dns.c
@@ -518,6 +518,7 @@ int _dns_decode_head(struct dns_context *context)
|
|||||||
head->nscount = dns_read_short(&context->ptr);
|
head->nscount = dns_read_short(&context->ptr);
|
||||||
head->nrcount = dns_read_short(&context->ptr);
|
head->nrcount = dns_read_short(&context->ptr);
|
||||||
|
|
||||||
|
printf("qd = %d, an = %d\n", head->qdcount, head->ancount);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,53 +545,6 @@ int _dns_encode_head(struct dns_context *context)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dns_parse_domain(char *dns, int offset, char *domain, int *space)
|
|
||||||
{
|
|
||||||
unsigned char val, *pval;
|
|
||||||
unsigned short len;
|
|
||||||
|
|
||||||
int sp = 0;
|
|
||||||
int domain_len = 0;
|
|
||||||
int org = 1;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
pval = (unsigned char *)(dns + offset);
|
|
||||||
val = *pval;
|
|
||||||
|
|
||||||
if (val == 0) {
|
|
||||||
domain[domain_len - 1] = 0;
|
|
||||||
domain_len--;
|
|
||||||
if (org)
|
|
||||||
sp++;
|
|
||||||
break;
|
|
||||||
} else if (val <= 63) {
|
|
||||||
memcpy(domain + domain_len, dns + offset + 1, val);
|
|
||||||
domain_len += val;
|
|
||||||
domain[domain_len] = '.';
|
|
||||||
domain_len++;
|
|
||||||
|
|
||||||
offset += (val + 1);
|
|
||||||
|
|
||||||
if (org)
|
|
||||||
sp += (val + 1);
|
|
||||||
} else {
|
|
||||||
len = *(unsigned short *)(dns + offset);
|
|
||||||
len = ntohs(len);
|
|
||||||
len = len & (~0xc000);
|
|
||||||
|
|
||||||
if (org)
|
|
||||||
sp += 2;
|
|
||||||
|
|
||||||
org = 0;
|
|
||||||
offset = len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*space = sp;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int _dns_decode_domain(struct dns_context *context, char *output, int size)
|
int _dns_decode_domain(struct dns_context *context, char *output, int size)
|
||||||
{
|
{
|
||||||
int output_len = 0;
|
int output_len = 0;
|
||||||
@@ -599,13 +553,6 @@ int _dns_decode_domain(struct dns_context *context, char *output, int size)
|
|||||||
unsigned char *ptr = context->ptr;
|
unsigned char *ptr = context->ptr;
|
||||||
int is_compressed = 0;
|
int is_compressed = 0;
|
||||||
|
|
||||||
|
|
||||||
int sp = 0;
|
|
||||||
dns_parse_domain(context->data, context->ptr - context->data, output, &sp);
|
|
||||||
context->ptr += sp;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
len = *ptr;
|
len = *ptr;
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
@@ -615,9 +562,15 @@ int _dns_decode_domain(struct dns_context *context, char *output, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (len >= 0xC0) {
|
if (len >= 0xC0) {
|
||||||
ptr = context->data + (dns_read_short(&ptr) & 0x3FFF);
|
len = dns_read_short(&ptr) & 0x3FFF;
|
||||||
|
if (is_compressed == 0) {
|
||||||
|
context->ptr = ptr;
|
||||||
|
}
|
||||||
|
ptr = context->data + len;
|
||||||
|
if (context->maxsize - (ptr - context->data) < 1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
is_compressed = 1;
|
is_compressed = 1;
|
||||||
context->ptr += 2;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,8 +598,6 @@ int _dns_decode_domain(struct dns_context *context, char *output, int size)
|
|||||||
context->ptr = ptr;
|
context->ptr = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("--%p\n", context->ptr);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user