Skip to content

Commit cc5ebd3

Browse files
author
yutianzuo
committed
opt code
1 parent 66399d2 commit cc5ebd3

File tree

1 file changed

+12
-4
lines changed
  • nativesock/src/main/cpp/netutils

1 file changed

+12
-4
lines changed

nativesock/src/main/cpp/netutils/dns.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,19 @@ class DNSQuery final : public SimpleUdpClient
283283
{
284284
return 2;
285285
}
286-
else
286+
else //this may be a label sequence, or label sequence + pointer(pointer must be the end of domain name)
287287
{
288288
int count = 0;
289289
for (auto c : str_response)
290290
{
291291
++count;
292-
if (c == 0)
292+
if (c == 0) // a label sequence
293+
{
294+
break;
295+
}
296+
else if (c & 0xc0) //end with a pointer
293297
{
298+
++count;
294299
break;
295300
}
296301
}
@@ -402,11 +407,12 @@ class DNSQuery final : public SimpleUdpClient
402407
}
403408
else
404409
{
410+
//if labels + pointer, then pointer must be the end of the domain name.
405411
if (jump & 0xc0) //encounter a pointer
406412
{
407413
//just move on
408414
++index_inner;
409-
jump = 0;
415+
return index_inner;
410416
}
411417
else
412418
{
@@ -447,7 +453,9 @@ class DNSQuery final : public SimpleUdpClient
447453
index_inner += 2;
448454
}
449455
else
450-
{ //name can be labels combines pointer, which is not handled
456+
{
457+
//name can be labels combines pointer, in which case pointer must be the end of domain name
458+
//str_host must be ignored
451459
index_inner = get_message_name(str_response, index_inner, str_host);
452460
}
453461

0 commit comments

Comments
 (0)