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
Diff: udp/dns/dnsquery.cpp
- Revision:
- 37:793b39683406
- Parent:
- 36:900e24b27bfb
- Child:
- 38:cc8945857a0d
diff -r 900e24b27bfb -r 793b39683406 udp/dns/dnsquery.cpp --- a/udp/dns/dnsquery.cpp Mon Sep 25 07:09:32 2017 +0000 +++ b/udp/dns/dnsquery.cpp Wed Oct 04 07:51:02 2017 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "log.h" #include "net.h" +#include "action.h" #include "ip4.h" #include "ip6.h" #include "dhcp.h" @@ -10,7 +11,7 @@ #include "dnshdr.h" #include "dnsname.h" -#define DEBUG false +bool DnsQueryTrace = false; #define TIME_OUT_SENT 3 @@ -128,7 +129,7 @@ if (!DnsQueryIsBusy) return DO_NOTHING; if (DnsQueryProtocol == DNS_PROTOCOL_UDNS && DhcpLocalIp == 0) return DO_NOTHING; - if (DEBUG) logQuery(); + if (DnsQueryTrace) logQuery(); static uint16_t id = 0; DnsHdrId = ++id; @@ -145,7 +146,7 @@ if (DnsQueryIp4 ) DnsNameEncodeIp4(DnsQueryIp4, &p); else if (DnsQueryIp6[0]) DnsNameEncodeIp6(DnsQueryIp6, &p); - else DnsNameEncode (DnsQueryName, &p); + else DnsNameEncodePtr(DnsQueryName, &p); *p++ = 0; *p++ = DnsQueryRecordType; @@ -156,13 +157,17 @@ DnsQueryIsBusy = false; + int dest = DO_NOTHING; + switch (DnsQueryProtocol) { - case DNS_PROTOCOL_UDNS: return UNICAST_DNS; //IPv6 ==> NdpDnsServer; IPv4 ==> DhcpDnsServer - case DNS_PROTOCOL_MDNS: return MULTICAST_MDNS; - case DNS_PROTOCOL_LLMNR: return MULTICAST_LLMNR; + case DNS_PROTOCOL_UDNS: dest = UNICAST_DNS; break; //IPv6 ==> NdpDnsServer; IPv4 ==> DhcpDnsServer + case DNS_PROTOCOL_MDNS: dest = MULTICAST_MDNS; break; + case DNS_PROTOCOL_LLMNR: dest = MULTICAST_LLMNR; break; default: LogTimeF("DNS unknown query protocol %d\r\n", DnsQueryProtocol); return DO_NOTHING; } + + return ActionMakeFromDestAndTrace(dest, DnsQueryTrace); }