Osvaldo Massanet / EthernetInterface

Dependencies:   Socket lwip-sys lwip

Fork of EthernetInterface by Miguel Urco

Files at this revision

API Documentation at this revision

Comitter:
miguelcordero191
Date:
Thu Jan 29 19:42:45 2015 +0000
Parent:
45:d1ccbed7687a
Child:
47:3b0a475eb1ad
Commit message:
A new method "set_net_addr" was added to EthernetInterface.

Changed in this revision

EthernetInterface.cpp Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Wed Dec 17 19:56:30 2014 +0000
+++ b/EthernetInterface.cpp	Thu Jan 29 19:42:45 2015 +0000
@@ -82,6 +82,12 @@
 #endif
 }
 
+static void set_new_addr(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
+    
+    netif_set_addr(&netif, ipaddr, netmask, gw);
+    
+}
+
 int EthernetInterface::init() {
     use_dhcp = true;
     set_mac_address();
@@ -104,6 +110,20 @@
     return 0;
 }
 
+int EthernetInterface::setNewAddr(const char* ip, const char* mask, const char* gateway) {
+    use_dhcp = false;
+    
+    strcpy(ip_addr, ip);
+    
+    ip_addr_t ip_n, mask_n, gateway_n;
+    inet_aton(ip, &ip_n);
+    inet_aton(mask, &mask_n);
+    inet_aton(gateway, &gateway_n);
+    set_new_addr(&ip_n, &mask_n, &gateway_n);
+    
+    return 0;
+}
+
 int EthernetInterface::connect(unsigned int timeout_ms) {
     eth_arch_enable_interrupts();
 
--- a/EthernetInterface.h	Wed Dec 17 19:56:30 2014 +0000
+++ b/EthernetInterface.h	Thu Jan 29 19:42:45 2015 +0000
@@ -47,6 +47,15 @@
   */
   static int init(const char* ip, const char* mask, const char* gateway);
 
+  /** Change the interface with a new static IP address.
+  * Change the interface and configure it with the following static configuration (no connection at this point).
+  * \param ip the IP address to use
+  * \param mask the IP address mask
+  * \param gateway the gateway to use
+  * \return 0 on success, a negative number on failure
+  */
+  static int setNewAddr(const char* ip, const char* mask, const char* gateway);
+  
   /** Connect
   * Bring the interface up, start DHCP if needed.
   * \param   timeout_ms  timeout in ms (default: (15)s).