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.c@200:5acbc41bf469, 2021-05-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu May 20 14:32:52 2021 +0000
- Revision:
- 200:5acbc41bf469
- Parent:
- 172:9bc3c7b2cca1
Increased number of arp entries from 20 to 30 to accommodate the number of WIZ devices plus a few incoming port 80 calls from the internet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdint.h> |
andrewboyson | 61:aad055f1b0d1 | 2 | #include <stdbool.h> |
andrewboyson | 61:aad055f1b0d1 | 3 | #include <string.h> |
andrewboyson | 61:aad055f1b0d1 | 4 | #include <stdio.h> |
andrewboyson | 61:aad055f1b0d1 | 5 | |
andrewboyson | 13:9cd54f7db57a | 6 | #include "dns.h" |
andrewboyson | 13:9cd54f7db57a | 7 | #include "dnshdr.h" |
andrewboyson | 13:9cd54f7db57a | 8 | #include "dnsquery.h" |
andrewboyson | 13:9cd54f7db57a | 9 | #include "dnsreply.h" |
andrewboyson | 13:9cd54f7db57a | 10 | #include "dnsserver.h" |
andrewboyson | 32:679654f2d023 | 11 | #include "log.h" |
andrewboyson | 32:679654f2d023 | 12 | #include "dhcp.h" |
andrewboyson | 13:9cd54f7db57a | 13 | |
andrewboyson | 83:08c983006a6e | 14 | |
andrewboyson | 83:08c983006a6e | 15 | bool DnsSendRequestsViaIp4 = false; |
andrewboyson | 83:08c983006a6e | 16 | |
andrewboyson | 47:73af5c0b0dc2 | 17 | void DnsProtocolString(uint8_t protocol, int size, char* text) |
andrewboyson | 13:9cd54f7db57a | 18 | { |
andrewboyson | 13:9cd54f7db57a | 19 | switch (protocol) |
andrewboyson | 13:9cd54f7db57a | 20 | { |
andrewboyson | 13:9cd54f7db57a | 21 | case DNS_PROTOCOL_UDNS: strncpy (text, "DNS", size); break; |
andrewboyson | 13:9cd54f7db57a | 22 | case DNS_PROTOCOL_MDNS: strncpy (text, "MDNS", size); break; |
andrewboyson | 13:9cd54f7db57a | 23 | case DNS_PROTOCOL_LLMNR: strncpy (text, "LLMNR", size); break; |
andrewboyson | 13:9cd54f7db57a | 24 | default: snprintf(text, size, "%d", protocol); break; |
andrewboyson | 13:9cd54f7db57a | 25 | } |
andrewboyson | 13:9cd54f7db57a | 26 | } |
andrewboyson | 13:9cd54f7db57a | 27 | |
andrewboyson | 47:73af5c0b0dc2 | 28 | void DnsRecordTypeString(uint8_t recordtype, int size, char* text) |
andrewboyson | 13:9cd54f7db57a | 29 | { |
andrewboyson | 13:9cd54f7db57a | 30 | switch (recordtype) |
andrewboyson | 13:9cd54f7db57a | 31 | { |
andrewboyson | 13:9cd54f7db57a | 32 | case DNS_RECORD_A: strncpy (text, "A", size); break; |
andrewboyson | 13:9cd54f7db57a | 33 | case DNS_RECORD_AAAA: strncpy (text, "AAAA", size); break; |
andrewboyson | 13:9cd54f7db57a | 34 | case DNS_RECORD_PTR: strncpy (text, "PTR", size); break; |
andrewboyson | 15:6ca6778168b1 | 35 | case DNS_RECORD_TXT: strncpy (text, "TXT", size); break; |
andrewboyson | 15:6ca6778168b1 | 36 | case DNS_RECORD_SRV: strncpy (text, "SRV", size); break; |
andrewboyson | 13:9cd54f7db57a | 37 | default: snprintf(text, size, "%d", recordtype); break; |
andrewboyson | 13:9cd54f7db57a | 38 | } |
andrewboyson | 13:9cd54f7db57a | 39 | } |
andrewboyson | 47:73af5c0b0dc2 | 40 | void DnsProtocolLog(uint8_t protocol) |
andrewboyson | 47:73af5c0b0dc2 | 41 | { |
andrewboyson | 47:73af5c0b0dc2 | 42 | switch (protocol) |
andrewboyson | 47:73af5c0b0dc2 | 43 | { |
andrewboyson | 47:73af5c0b0dc2 | 44 | case DNS_PROTOCOL_UDNS: Log ("DNS "); break; |
andrewboyson | 47:73af5c0b0dc2 | 45 | case DNS_PROTOCOL_MDNS: Log ("MDNS "); break; |
andrewboyson | 47:73af5c0b0dc2 | 46 | case DNS_PROTOCOL_LLMNR: Log ("LLMNR"); break; |
andrewboyson | 47:73af5c0b0dc2 | 47 | default: LogF("%d", protocol); break; |
andrewboyson | 47:73af5c0b0dc2 | 48 | } |
andrewboyson | 47:73af5c0b0dc2 | 49 | } |
andrewboyson | 47:73af5c0b0dc2 | 50 | |
andrewboyson | 47:73af5c0b0dc2 | 51 | void DnsRecordTypeLog(uint8_t recordtype) |
andrewboyson | 47:73af5c0b0dc2 | 52 | { |
andrewboyson | 47:73af5c0b0dc2 | 53 | switch (recordtype) |
andrewboyson | 47:73af5c0b0dc2 | 54 | { |
andrewboyson | 47:73af5c0b0dc2 | 55 | case DNS_RECORD_A: Log ("A" ); break; |
andrewboyson | 47:73af5c0b0dc2 | 56 | case DNS_RECORD_AAAA: Log ("AAAA"); break; |
andrewboyson | 47:73af5c0b0dc2 | 57 | case DNS_RECORD_PTR: Log ("PTR" ); break; |
andrewboyson | 47:73af5c0b0dc2 | 58 | case DNS_RECORD_TXT: Log ("TXT" ); break; |
andrewboyson | 47:73af5c0b0dc2 | 59 | case DNS_RECORD_SRV: Log ("SRV" ); break; |
andrewboyson | 47:73af5c0b0dc2 | 60 | default: LogF("%d", recordtype); break; |
andrewboyson | 47:73af5c0b0dc2 | 61 | } |
andrewboyson | 47:73af5c0b0dc2 | 62 | } |
andrewboyson | 13:9cd54f7db57a | 63 | |
andrewboyson | 43:bc028d5a6424 | 64 | void DnsMain() |
andrewboyson | 13:9cd54f7db57a | 65 | { |
andrewboyson | 43:bc028d5a6424 | 66 | DnsQueryMain(); |
andrewboyson | 13:9cd54f7db57a | 67 | } |
andrewboyson | 13:9cd54f7db57a | 68 | |
andrewboyson | 59:e0e556c8bd46 | 69 | int DnsHandlePacketReceived(void (*traceback)(void), int dnsProtocol, int sizeRx, void* pPacketRx, int* pSizeTx, void* pPacketTx) |
andrewboyson | 13:9cd54f7db57a | 70 | { |
andrewboyson | 59:e0e556c8bd46 | 71 | DnsHdrSetup(pPacketRx, sizeRx); |
andrewboyson | 13:9cd54f7db57a | 72 | DnsHdrRead(); |
andrewboyson | 59:e0e556c8bd46 | 73 | |
andrewboyson | 13:9cd54f7db57a | 74 | int action; |
andrewboyson | 13:9cd54f7db57a | 75 | if (DnsHdrIsReply) |
andrewboyson | 13:9cd54f7db57a | 76 | { |
andrewboyson | 59:e0e556c8bd46 | 77 | action = DnsReplyHandle(traceback, dnsProtocol); |
andrewboyson | 13:9cd54f7db57a | 78 | } |
andrewboyson | 13:9cd54f7db57a | 79 | else |
andrewboyson | 13:9cd54f7db57a | 80 | { |
andrewboyson | 59:e0e556c8bd46 | 81 | action = DnsServerHandleQuery(traceback, dnsProtocol, pPacketTx, pSizeTx); |
andrewboyson | 13:9cd54f7db57a | 82 | } |
andrewboyson | 13:9cd54f7db57a | 83 | return action; |
andrewboyson | 13:9cd54f7db57a | 84 | } |
andrewboyson | 13:9cd54f7db57a | 85 | |
andrewboyson | 171:f708d6776752 | 86 | int DnsPollForPacketToSend(int ipType, void* pPacketTx, int* pSize) |
andrewboyson | 13:9cd54f7db57a | 87 | { |
andrewboyson | 171:f708d6776752 | 88 | return DnsQueryPoll(ipType, pPacketTx, pSize); |
andrewboyson | 13:9cd54f7db57a | 89 | } |