mbed IP library over Ethernet with setName and setNewAddress

Dependencies:   Socket lwip-eth lwip-sys lwip

Dependents:   JRO_CR2 JRO_DDSv2 JRO_DDSv2_rev2019

Fork of EthernetInterface by mbed official

Revision:
47:3b0a475eb1ad
Parent:
46:4cb91998b200
Child:
48:303f4d8389a1
--- a/EthernetInterface.cpp	Thu Jan 29 19:42:45 2015 +0000
+++ b/EthernetInterface.cpp	Thu Feb 05 19:02:23 2015 +0000
@@ -35,6 +35,7 @@
 static char gateway[17] = "\0";
 static char networkmask[17] = "\0";
 static bool use_dhcp = false;
+static char myName[33];  // holds the name, when setName() is called.
 
 static Semaphore tcpip_inited(0);
 static Semaphore netif_linked(0);
@@ -124,6 +125,24 @@
     return 0;
 }
 
+int EthernetInterface::setName(const char * myname) {
+    int i;
+    
+    strncpy(myName, myname, 32);
+    myName[32] = '\0';  // be sure it is NULL terminated.
+    // make the name 'safe'
+    /*
+    for (i=0; i<32 && myName[i]; i++) {
+        if (!inRange(myName[i], '0', '9')
+        &&  !inRange(myName[i], 'A', 'Z')
+        &&  !inRange(myName[i], 'a', 'z'))
+            myName[i] = '-';
+    }
+    */
+    netif_set_hostname(&netif, myName);
+    return 0;
+}
+
 int EthernetInterface::connect(unsigned int timeout_ms) {
     eth_arch_enable_interrupts();