A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Tue May 09 15:39:03 2017 +0000
Revision:
15:6ca6778168b1
Parent:
13:9cd54f7db57a
Child:
32:679654f2d023
Tidied up dns debug output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 13:9cd54f7db57a 1 #include "dns.h"
andrewboyson 13:9cd54f7db57a 2 #include "dnshdr.h"
andrewboyson 13:9cd54f7db57a 3 #include "dnsquery.h"
andrewboyson 13:9cd54f7db57a 4 #include "dnsreply.h"
andrewboyson 13:9cd54f7db57a 5 #include "dnsserver.h"
andrewboyson 13:9cd54f7db57a 6 #include "io.h"
andrewboyson 13:9cd54f7db57a 7
andrewboyson 13:9cd54f7db57a 8 void DnsProtocolToString(uint8_t protocol, int size, char* text)
andrewboyson 13:9cd54f7db57a 9 {
andrewboyson 13:9cd54f7db57a 10 switch (protocol)
andrewboyson 13:9cd54f7db57a 11 {
andrewboyson 13:9cd54f7db57a 12 case DNS_PROTOCOL_UDNS: strncpy (text, "DNS", size); break;
andrewboyson 13:9cd54f7db57a 13 case DNS_PROTOCOL_MDNS: strncpy (text, "MDNS", size); break;
andrewboyson 13:9cd54f7db57a 14 case DNS_PROTOCOL_LLMNR: strncpy (text, "LLMNR", size); break;
andrewboyson 13:9cd54f7db57a 15 default: snprintf(text, size, "%d", protocol); break;
andrewboyson 13:9cd54f7db57a 16 }
andrewboyson 13:9cd54f7db57a 17 }
andrewboyson 13:9cd54f7db57a 18
andrewboyson 13:9cd54f7db57a 19 void DnsRecordTypeToString(uint8_t recordtype, int size, char* text)
andrewboyson 13:9cd54f7db57a 20 {
andrewboyson 13:9cd54f7db57a 21 switch (recordtype)
andrewboyson 13:9cd54f7db57a 22 {
andrewboyson 13:9cd54f7db57a 23 case DNS_RECORD_A: strncpy (text, "A", size); break;
andrewboyson 13:9cd54f7db57a 24 case DNS_RECORD_AAAA: strncpy (text, "AAAA", size); break;
andrewboyson 13:9cd54f7db57a 25 case DNS_RECORD_PTR: strncpy (text, "PTR", size); break;
andrewboyson 15:6ca6778168b1 26 case DNS_RECORD_TXT: strncpy (text, "TXT", size); break;
andrewboyson 15:6ca6778168b1 27 case DNS_RECORD_SRV: strncpy (text, "SRV", size); break;
andrewboyson 13:9cd54f7db57a 28 default: snprintf(text, size, "%d", recordtype); break;
andrewboyson 13:9cd54f7db57a 29 }
andrewboyson 13:9cd54f7db57a 30 }
andrewboyson 13:9cd54f7db57a 31
andrewboyson 13:9cd54f7db57a 32 void DnsTick()
andrewboyson 13:9cd54f7db57a 33 {
andrewboyson 13:9cd54f7db57a 34 DnsQueryTick();
andrewboyson 13:9cd54f7db57a 35 }
andrewboyson 13:9cd54f7db57a 36
andrewboyson 13:9cd54f7db57a 37 int DnsHandlePacketReceived(int dnsProtocol, int* pSize, void* pPacket)
andrewboyson 13:9cd54f7db57a 38 {
andrewboyson 13:9cd54f7db57a 39 DnsHdrSetup(pPacket);
andrewboyson 13:9cd54f7db57a 40 DnsHdrRead();
andrewboyson 13:9cd54f7db57a 41 int action;
andrewboyson 13:9cd54f7db57a 42 if (DnsHdrIsReply)
andrewboyson 13:9cd54f7db57a 43 {
andrewboyson 13:9cd54f7db57a 44 action = DnsReplyHandle(dnsProtocol, pSize);
andrewboyson 13:9cd54f7db57a 45 }
andrewboyson 13:9cd54f7db57a 46 else
andrewboyson 13:9cd54f7db57a 47 {
andrewboyson 13:9cd54f7db57a 48 action = DnsServerHandleQuery(dnsProtocol, pSize);
andrewboyson 13:9cd54f7db57a 49 }
andrewboyson 13:9cd54f7db57a 50 return action;
andrewboyson 13:9cd54f7db57a 51 }
andrewboyson 13:9cd54f7db57a 52
andrewboyson 13:9cd54f7db57a 53 int DnsPollForPacketToSend(void* pPacket, int* pSize)
andrewboyson 13:9cd54f7db57a 54 {
andrewboyson 13:9cd54f7db57a 55 DnsHdrSetup(pPacket);
andrewboyson 13:9cd54f7db57a 56 return DnsQueryPoll(pSize);
andrewboyson 13:9cd54f7db57a 57 }