Skip to content

Commit

Permalink
DNS-SD, back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Aug 14, 2024
1 parent ea0e15b commit 27b1207
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Protest/Protocols/Mdns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static byte[] Resolve(string queryString, int timeout = 2000, RecordType
List<byte[]> matchingData = new List<byte[]>();
List<Answer> answers = new List<Answer>();

/*try*/ {
try {
for (int i = 0; i < receivedData.Count; i++) {
byte[] response = receivedData[i];
ushort answerCount, authorityCount, additionalCount;
Expand All @@ -146,9 +146,9 @@ public static byte[] Resolve(string queryString, int timeout = 2000, RecordType
}
}
}
/*catch {
catch {
return "{\"error\":\"unknown error\",\"errorcode\":\"0\"}"u8.ToArray();
}*/
}

return Serialize(query, matchingData, answers);
}
Expand Down Expand Up @@ -337,8 +337,8 @@ private static Answer[] ParseAnswers(byte[] response, RecordType queryType, IPAd

case RecordType.SRV:
if (index + 6 <= response.Length) {
//ans.priority = (ushort)((response[index] << 8) | response[index + 1]);
//ans.weight = (ushort)((response[index+2] << 8) | response[index + 3]);
//priority = (ushort)((response[index] << 8) | response[index + 1]);
//weight = (ushort)((response[index+2] << 8) | response[index + 3]);
ushort port = (ushort)((response[index+4] << 8) | response[index + 5]);
answer.answerString = ExtractName(response, index + 6) + ":" + port;
}
Expand Down Expand Up @@ -374,14 +374,14 @@ private static string ExtractName(byte[] response, int startIndex) {
int length = 0;

while (index < response.Length && response[index] != 0) {
if ((response[index] & 0xC0) == 0xC0) { // is pointer
if ((response[index] & 0xC0) == 0xC0) { //pointer
int pointer = ((response[index] & 0x3F) << 8) | response[index + 1];
length += ExtractName(response, pointer).Length;
break;
}
else {
int labelLength = response[index++];
length += labelLength + 1; // label length + dot
length += labelLength + 1; // label + dot
index += labelLength;
}
}
Expand Down

0 comments on commit 27b1207

Please sign in to comment.