From 7fd6ec42b63390702ff5c7b0422c1aa487e0c100 Mon Sep 17 00:00:00 2001 From: Walter Stanish <505366+globalcitizen@users.noreply.github.com> Date: Mon, 21 Feb 2022 11:24:26 +0800 Subject: [PATCH] Add option to exclude DNS features. --- src/EtherCard.cpp | 2 ++ src/EtherCard.h | 6 ++++++ src/dns.cpp | 2 ++ src/tcpip.cpp | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/src/EtherCard.cpp b/src/EtherCard.cpp index f752a9bf..9b72d8c8 100644 --- a/src/EtherCard.cpp +++ b/src/EtherCard.cpp @@ -21,7 +21,9 @@ uint8_t EtherCard::netmask[IP_LEN]; // subnet mask uint8_t EtherCard::broadcastip[IP_LEN]; // broadcast address uint8_t EtherCard::gwip[IP_LEN]; // gateway uint8_t EtherCard::dhcpip[IP_LEN]; // dhcp server +#if ETHERCARD_DNS uint8_t EtherCard::dnsip[IP_LEN]; // dns server +#endif uint8_t EtherCard::hisip[IP_LEN]; // ip address of remote host uint16_t EtherCard::hisport = HTTP_PORT; // tcp port to browse to bool EtherCard::using_dhcp = false; diff --git a/src/EtherCard.h b/src/EtherCard.h index 703b5990..fd3f5868 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -49,6 +49,12 @@ */ #define ETHERCARD_DHCP 1 +/** Enable DNS. +* Setting this to zero disables the use of DNS; if a program uses DNS it will +* not compile. Saves 6 bytes SRAM, 110 bytes flash, and some packet processing overhead. +*/ +#define ETHERCARD_DNS 1 + /** Enable client connections. * Setting this to zero means that the program cannot issue TCP client requests * anymore. Compilation will still work but the request will never be diff --git a/src/dns.cpp b/src/dns.cpp index 3909c6a0..237dd57b 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -4,6 +4,7 @@ // // 2010-05-20 +#if ETHERCARD_DNS #include "EtherCard.h" #include "net.h" @@ -118,3 +119,4 @@ bool EtherCard::dnsLookup (const char* name, bool fromRam) { return true; } +#endif diff --git a/src/tcpip.cpp b/src/tcpip.cpp index 6dbd0957..e39087e7 100644 --- a/src/tcpip.cpp +++ b/src/tcpip.cpp @@ -50,8 +50,10 @@ static const char *client_urlbuf_var; // Pointer to c-string filename part of HT static const char *client_hoststr; // Pointer to c-string hostname of current HTTP request static void (*icmp_cb)(uint8_t *ip); // Pointer to callback function for ICMP ECHO response handler (triggers when localhost receives ping response (pong)) static uint8_t destmacaddr[ETH_LEN]; // storing both dns server and destination mac addresses, but at different times because both are never needed at same time. +#if ETHERCARD_DNS static boolean waiting_for_dns_mac = false; //might be better to use bit flags and bitmask operations for these conditions static boolean has_dns_mac = false; +#endif static boolean waiting_for_dest_mac = false; static boolean has_dest_mac = false; static uint8_t gwmacaddr[ETH_LEN]; // Hardware (MAC) address of gateway router @@ -459,11 +461,13 @@ uint8_t EtherCard::clientWaitingGw () { return !(waitgwmac & WGW_HAVE_GW_MAC); } +#if ETHERCARD_DNS uint8_t EtherCard::clientWaitingDns () { if(is_lan(myip, dnsip)) return !has_dns_mac; return !(waitgwmac & WGW_HAVE_GW_MAC); } +#endif static uint8_t client_store_mac(uint8_t *source_ip, uint8_t *mac) { if (memcmp(gPB + ETH_ARP_SRC_IP_P, source_ip, IP_LEN) != 0) @@ -697,11 +701,13 @@ uint16_t EtherCard::packetLoop (uint16_t plen) { } #endif +#if ETHERCARD_DNS //!@todo this is trying to find mac only once. Need some timeout to make another call if first one doesn't succeed. if(is_lan(myip, dnsip) && !has_dns_mac && !waiting_for_dns_mac) { client_arp_whohas(dnsip); waiting_for_dns_mac = true; } +#endif //!@todo this is trying to find mac only once. Need some timeout to make another call if first one doesn't succeed. if(is_lan(myip, hisip) && !has_dest_mac && !waiting_for_dest_mac) { @@ -718,10 +724,12 @@ uint16_t EtherCard::packetLoop (uint16_t plen) { make_arp_answer_from_request(); if (waitgwmac & WGW_ACCEPT_ARP_REPLY && (gPB[ETH_ARP_OPCODE_L_P]==ETH_ARP_OPCODE_REPLY_L_V) && client_store_mac(gwip, gwmacaddr)) waitgwmac = WGW_HAVE_GW_MAC; +#if ETHERCARD_DNS if (!has_dns_mac && waiting_for_dns_mac && client_store_mac(dnsip, destmacaddr)) { has_dns_mac = true; waiting_for_dns_mac = false; } +#endif if (!has_dest_mac && waiting_for_dest_mac && client_store_mac(hisip, destmacaddr)) { has_dest_mac = true; waiting_for_dest_mac = false;