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
udp/dns/dns.cpp
- Committer:
- andrewboyson
- Date:
- 2017-05-09
- Revision:
- 15:6ca6778168b1
- Parent:
- 13:9cd54f7db57a
- Child:
- 32:679654f2d023
File content as of revision 15:6ca6778168b1:
#include "dns.h" #include "dnshdr.h" #include "dnsquery.h" #include "dnsreply.h" #include "dnsserver.h" #include "io.h" void DnsProtocolToString(uint8_t protocol, int size, char* text) { switch (protocol) { case DNS_PROTOCOL_UDNS: strncpy (text, "DNS", size); break; case DNS_PROTOCOL_MDNS: strncpy (text, "MDNS", size); break; case DNS_PROTOCOL_LLMNR: strncpy (text, "LLMNR", size); break; default: snprintf(text, size, "%d", protocol); break; } } void DnsRecordTypeToString(uint8_t recordtype, int size, char* text) { switch (recordtype) { case DNS_RECORD_A: strncpy (text, "A", size); break; case DNS_RECORD_AAAA: strncpy (text, "AAAA", size); break; case DNS_RECORD_PTR: strncpy (text, "PTR", size); break; case DNS_RECORD_TXT: strncpy (text, "TXT", size); break; case DNS_RECORD_SRV: strncpy (text, "SRV", size); break; default: snprintf(text, size, "%d", recordtype); break; } } void DnsTick() { DnsQueryTick(); } int DnsHandlePacketReceived(int dnsProtocol, int* pSize, void* pPacket) { DnsHdrSetup(pPacket); DnsHdrRead(); int action; if (DnsHdrIsReply) { action = DnsReplyHandle(dnsProtocol, pSize); } else { action = DnsServerHandleQuery(dnsProtocol, pSize); } return action; } int DnsPollForPacketToSend(void* pPacket, int* pSize) { DnsHdrSetup(pPacket); return DnsQueryPoll(pSize); }