Forked ethernet interface library

Dependencies:   Socket lwip-eth lwip-sys lwip

Dependents:   CI-data-logger-server

Fork of EthernetInterface by mbed official

Files at this revision

API Documentation at this revision

Comitter:
thedude35
Date:
Sun Jun 18 03:31:42 2017 +0000
Parent:
54:183490eb1b4a
Commit message:
Initial commit

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 May 11 22:18:04 2016 +0000
+++ b/EthernetInterface.cpp	Sun Jun 18 03:31:42 2017 +0000
@@ -26,6 +26,7 @@
 #include "lwip/tcpip.h"
 
 #include "mbed.h"
+#include "string.h"
 
 /* TCP/IP and Network Interface Initialisation */
 static struct netif netif;
@@ -35,6 +36,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);
@@ -137,6 +139,22 @@
     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;
+}
+
 char* EthernetInterface::getMACAddress() {
     return mac_addr;
 }
--- a/EthernetInterface.h	Wed May 11 22:18:04 2016 +0000
+++ b/EthernetInterface.h	Sun Jun 18 03:31:42 2017 +0000
@@ -79,6 +79,20 @@
    * \return a pointer to a string containing the Network mask
    */
   static char* getNetworkMask();
+  
+  /** setName 
+  *
+  * Set the network name for this device. Apply this before
+  * calling 'connect'.
+  *
+  * \param myname is the name to assign for this node. 
+  *        Only the first 32 characters will be used if the 
+  *        name is longer.
+  *        Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted,
+  *        any others are converted to '-'.
+  * \return 0 on success, a negative number on failure.
+  */
+  static int setName(const char * myname);
 };
 
 #include "TCPSocketConnection.h"