Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: udp/dns/dnsserver.c
- Revision:
- 178:52714fef5ca1
- Parent:
- 177:2cd7fde8bfe5
- Child:
- 189:e1c7990486c4
--- a/udp/dns/dnsserver.c Sun Dec 27 17:26:21 2020 +0000
+++ b/udp/dns/dnsserver.c Tue Dec 29 19:14:35 2020 +0000
@@ -6,6 +6,7 @@
#include "dnsname.h"
#include "dnslabel.h"
#include "net.h"
+#include "net-this.h"
#include "action.h"
#include "log.h"
#include "dhcp.h"
@@ -29,10 +30,8 @@
//Set by 'initialise'
static char* p; //Position relative to DnsHdrData and is updated while both reading questions and writing answers
-static char myFullName4[100]; //The name, adjusted to include the domain if needed by the protocol, used when reading and when writing
-static int myFullName4Length;
-static char myFullName6[100]; //The name, adjusted to include the domain if needed by the protocol, used when reading and when writing
-static int myFullName6Length;
+static char myFullName[100]; //The name, adjusted to include the domain if needed by the protocol, used when reading and when writing
+static int myFullNameLength;
//Set by readQuestions and used by answerQuestions
static int answers[MAX_ANSWERS];
@@ -69,8 +68,7 @@
if (DnsServerTrace) LogTimeF("DnsServer-readQuestions namelength is zero\r\n");
return -1;
}
- bool nodeIsName4 = DnsNameComparePtr(p, myFullName4);
- bool nodeIsName6 = DnsNameComparePtr(p, myFullName6);
+ bool nodeIsName = DnsNameComparePtr(p, myFullName);
bool nodeIsAddr4 = DnsNameCompareIp4(p, DhcpLocalIp);
bool nodeIsLocl6 = DnsNameCompareIp6(p, SlaacLinkLocalIp);
bool nodeIsUniq6 = DnsNameCompareIp6(p, SlaacUniqueLocalIp);
@@ -86,17 +84,17 @@
p++; //skip the class
//Handle the questions
- if (nodeIsName4 && recordType == DNS_RECORD_A ) answers[answerCount++] = RECORD_A;
- if (nodeIsName6 && recordType == DNS_RECORD_AAAA)
+ if (nodeIsName && recordType == DNS_RECORD_A ) answers[answerCount++] = RECORD_A;
+ if (nodeIsName && recordType == DNS_RECORD_AAAA)
{
- answers[answerCount++] = RECORD_AAAA_LINK_LOCAL;
- if (SlaacUniqueLocalIp[0]) answers[answerCount++] = RECORD_AAAA_UNIQUE_LOCAL;
- if (SlaacGlobalIp [0]) answers[answerCount++] = RECORD_AAAA_GLOBAL;
+ answers[answerCount++] = RECORD_AAAA_LINK_LOCAL;
+ if (SlaacUniqueLocalIp[0]) answers[answerCount++] = RECORD_AAAA_UNIQUE_LOCAL;
+ if (SlaacGlobalIp [0]) answers[answerCount++] = RECORD_AAAA_GLOBAL;
}
- if (nodeIsAddr4 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR4;
- if (nodeIsLocl6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_LINK_LOCAL;
- if (nodeIsUniq6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_UNIQUE_LOCAL;
- if (nodeIsGlob6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_GLOBAL;
+ if (nodeIsAddr4 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR4;
+ if (nodeIsLocl6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_LINK_LOCAL;
+ if (nodeIsUniq6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_UNIQUE_LOCAL;
+ if (nodeIsGlob6 && recordType == DNS_RECORD_PTR ) answers[answerCount++] = RECORD_PTR6_GLOBAL;
}
return 0;
}
@@ -116,10 +114,10 @@
//Encode the node name
switch (answers[i])
{
- case RECORD_A: DnsNameEncodePtr(myFullName4, &p); break;
- case RECORD_AAAA_LINK_LOCAL: DnsNameEncodePtr(myFullName6, &p); break;
- case RECORD_AAAA_UNIQUE_LOCAL: DnsNameEncodePtr(myFullName6, &p); break;
- case RECORD_AAAA_GLOBAL: DnsNameEncodePtr(myFullName6, &p); break;
+ case RECORD_A: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_AAAA_LINK_LOCAL: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_AAAA_UNIQUE_LOCAL: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_AAAA_GLOBAL: DnsNameEncodePtr(myFullName, &p); break;
case RECORD_PTR4: DnsNameEncodeIp4(DhcpLocalIp, &p); break;
case RECORD_PTR6_LINK_LOCAL: DnsNameEncodeIp6(SlaacLinkLocalIp, &p); break;
case RECORD_PTR6_UNIQUE_LOCAL: DnsNameEncodeIp6(SlaacUniqueLocalIp, &p); break;
@@ -152,14 +150,14 @@
*p++ = 0;
switch (answers[i])
{
- case RECORD_A: *p++ = 4; break;
- case RECORD_AAAA_LINK_LOCAL: *p++ = 16; break;
- case RECORD_AAAA_UNIQUE_LOCAL: *p++ = 16; break;
- case RECORD_AAAA_GLOBAL: *p++ = 16; break;
- case RECORD_PTR4: *p++ = myFullName4Length + 2; break; //add a byte for the initial length and another for the terminating zero length
- case RECORD_PTR6_LINK_LOCAL: *p++ = myFullName6Length + 2; break;
- case RECORD_PTR6_UNIQUE_LOCAL: *p++ = myFullName6Length + 2; break;
- case RECORD_PTR6_GLOBAL: *p++ = myFullName6Length + 2; break;
+ case RECORD_A: *p++ = 4; break;
+ case RECORD_AAAA_LINK_LOCAL: *p++ = 16; break;
+ case RECORD_AAAA_UNIQUE_LOCAL: *p++ = 16; break;
+ case RECORD_AAAA_GLOBAL: *p++ = 16; break;
+ case RECORD_PTR4: *p++ = myFullNameLength + 2; break; //add a byte for the initial length and another for the terminating zero length
+ case RECORD_PTR6_LINK_LOCAL: *p++ = myFullNameLength + 2; break;
+ case RECORD_PTR6_UNIQUE_LOCAL: *p++ = myFullNameLength + 2; break;
+ case RECORD_PTR6_GLOBAL: *p++ = myFullNameLength + 2; break;
}
//Add the payload
@@ -169,10 +167,10 @@
case RECORD_AAAA_LINK_LOCAL: memcpy(p, SlaacLinkLocalIp, 16); p += 16; break;
case RECORD_AAAA_UNIQUE_LOCAL: memcpy(p, SlaacUniqueLocalIp, 16); p += 16; break;
case RECORD_AAAA_GLOBAL: memcpy(p, SlaacGlobalIp, 16); p += 16; break;
- case RECORD_PTR4: DnsNameEncodePtr(myFullName4, &p); break;
- case RECORD_PTR6_LINK_LOCAL: DnsNameEncodePtr(myFullName6, &p); break;
- case RECORD_PTR6_UNIQUE_LOCAL: DnsNameEncodePtr(myFullName6, &p); break;
- case RECORD_PTR6_GLOBAL: DnsNameEncodePtr(myFullName6, &p); break;
+ case RECORD_PTR4: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_PTR6_LINK_LOCAL: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_PTR6_UNIQUE_LOCAL: DnsNameEncodePtr(myFullName, &p); break;
+ case RECORD_PTR6_GLOBAL: DnsNameEncodePtr(myFullName, &p); break;
}
//Increment the number of good answers to send
DnsHdrAncount++;
@@ -182,8 +180,7 @@
int DnsServerHandleQuery(void (*traceback)(void), int dnsProtocol, void* pPacketTx, int *pSizeTx) //Received an mdns or llmnr query on port 5353 or 5355
{
- myFullName4Length = DnsLabelMakeFullNameFromName(dnsProtocol, NetName4, sizeof(myFullName4), myFullName4);
- myFullName6Length = DnsLabelMakeFullNameFromName(dnsProtocol, NetName6, sizeof(myFullName6), myFullName6);
+ myFullNameLength = DnsLabelMakeFullNameFromName(dnsProtocol, NET_NAME, sizeof(myFullName), myFullName);
if (readQuestions()) return DO_NOTHING;
if (!answerCount) return DO_NOTHING;