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
Revision 178:52714fef5ca1, committed 2020-12-29
- Comitter:
- andrewboyson
- Date:
- Tue Dec 29 19:14:35 2020 +0000
- Parent:
- 177:2cd7fde8bfe5
- Child:
- 179:55342264fca1
- Commit message:
- Included host name in DHCP request option 12 to allow my Sky router to display the host name instead of 'UNKNOWN'. Also removed different host names for IPv4 and IPv6.
Changed in this revision
--- a/net.c Sun Dec 27 17:26:21 2020 +0000
+++ b/net.c Tue Dec 29 19:14:35 2020 +0000
@@ -20,8 +20,6 @@
bool NetTraceStack = false;
bool NetTraceNewLine = false;
bool NetTraceVerbose = false;
-const char* NetName4;
-const char* NetName6;
static bool hostMatched = false;
bool NetTraceHostGetMatched()
@@ -155,10 +153,8 @@
*ph = *pn; ph++; pn++; // 6<-6
*ph = *pn; // 7<-7
}
-void NetInit(const char* name4, const char* name6)
-{
- NetName4 = name4;
- NetName6 = name6;
+void NetInit()
+{
LinkInit();
TcpInit();
Ar4Init();
--- a/net.h Sun Dec 27 17:26:21 2020 +0000 +++ b/net.h Tue Dec 29 19:14:35 2020 +0000 @@ -20,12 +20,9 @@ extern void NetDirect32(void* h, void* n); extern void NetDirect64(void* h, void* n); -extern void NetInit(const char* name4, const char* name6); +extern void NetInit(void); extern void NetMain(void); -extern const char* NetName4; -extern const char* NetName6; - #define FAULT_POINT_NetMain 1 #define FAULT_POINT_LinkMain 2 #define FAULT_POINT_EthHandlePacket 3
--- a/udp/dhcp/dhcp.c Sun Dec 27 17:26:21 2020 +0000
+++ b/udp/dhcp/dhcp.c Tue Dec 29 19:14:35 2020 +0000
@@ -5,6 +5,7 @@
#include "log.h"
#include "mstimer.h"
#include "net.h"
+#include "net-this.h"
#include "action.h"
#include "eth.h"
#include "ip4addr.h"
@@ -155,6 +156,27 @@
*pp += 6;
}
+static void writeText(uint8_t code, const char* pText, char** pp)
+{
+ if (!pText) return;
+ if (!*pText) return;
+
+ char* p = *pp;
+
+ *p++ = code;
+ char* pLength = p++;
+ while (true) //Copy pText without the end zero
+ {
+ *p = *pText;
+ pText++;
+ if (!*pText) break;
+ p++;
+ }
+
+ *pLength = p - pLength;
+
+ *pp += *pLength + 2;
+}
int sendRequest(void* pPacket, uint8_t code, uint32_t srvIp, uint32_t reqIp)
{
@@ -204,6 +226,8 @@
writeIp(50, reqIp, &p); //Requested IP
writeIp(54, srvIp, &p); //Server ip
+
+ writeText(12, NET_NAME, &p);
*p++ = 255; //End of options
--- 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;