1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
   | 
 
  #if LWIP_FEATURES && !LWIP_IPV6
  #define HAVE_NETDUMP 0
  #ifndef STASSID #define STASSID "mynetwork" #define STAPSK  "mynetworkpassword" #endif
  #include <ESP8266WiFi.h> #include <lwip/napt.h> #include <lwip/dns.h> #include <LwipDhcpServer.h>
  #define NAPT 1000 #define NAPT_PORT 10
  #if HAVE_NETDUMP
  #include <NetDump.h>
  void dump(int netif_idx, const char* data, size_t len, int out, int success) {   (void)success;   Serial.print(out ? F("out ") : F(" in "));   Serial.printf("%d ", netif_idx);
       {     netDump(Serial, data, len);        } } #endif
  void setup() {   Serial.begin(115200);   Serial.printf("\n\nNAPT Range extender\n");   Serial.printf("Heap on start: %d\n", ESP.getFreeHeap());
  #if HAVE_NETDUMP   phy_capture = dump; #endif
       WiFi.mode(WIFI_STA);   WiFi.begin(STASSID, STAPSK);   while (WiFi.status() != WL_CONNECTED) {     Serial.print('.');     delay(500);   }   Serial.printf("\nSTA: %s (dns: %s / %s)\n",                 WiFi.localIP().toString().c_str(),                 WiFi.dnsIP(0).toString().c_str(),                 WiFi.dnsIP(1).toString().c_str());
       dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));   dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));
    WiFi.softAPConfig(       IPAddress(172, 217, 28, 254),     IPAddress(172, 217, 28, 254),     IPAddress(255, 255, 255, 0));   WiFi.softAP(STASSID "extender", STAPSK);   Serial.printf("AP: %s\n", WiFi.softAPIP().toString().c_str());
    Serial.printf("Heap before: %d\n", ESP.getFreeHeap());   err_t ret = ip_napt_init(NAPT, NAPT_PORT);   Serial.printf("ip_napt_init(%d,%d): ret=%d (OK=%d)\n", NAPT, NAPT_PORT, (int)ret, (int)ERR_OK);   if (ret == ERR_OK) {     ret = ip_napt_enable_no(SOFTAP_IF, 1);     Serial.printf("ip_napt_enable_no(SOFTAP_IF): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);     if (ret == ERR_OK) {       Serial.printf("WiFi Network '%s' with same password is now NATed behind '%s'\n", STASSID "extender", STASSID);     }   }   Serial.printf("Heap after napt init: %d\n", ESP.getFreeHeap());   if (ret != ERR_OK) {     Serial.printf("NAPT initialization failed\n");   } }
  #else
  void setup() {   Serial.begin(115200);   Serial.printf("\n\nNAPT not supported in this configuration\n"); }
  #endif
  void loop() { }
 
 
  |