Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Socket lwip-sys lwip
Fork of EthernetInterface by
Revision 47:3b0a475eb1ad, committed 2015-02-05
- Comitter:
- miguelcordero191
- Date:
- Thu Feb 05 19:02:23 2015 +0000
- Parent:
- 46:4cb91998b200
- Child:
- 48:303f4d8389a1
- Commit message:
- setName and changeIp methods were added
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 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();
--- a/EthernetInterface.h Thu Jan 29 19:42:45 2015 +0000 +++ b/EthernetInterface.h Thu Feb 05 19:02:23 2015 +0000 @@ -55,12 +55,27 @@ * \return 0 on success, a negative number on failure */ static int setNewAddr(const char* ip, const char* mask, const char* gateway); + +/** 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); /** Connect * Bring the interface up, start DHCP if needed. * \param timeout_ms timeout in ms (default: (15)s). * \return 0 on success, a negative number on failure */ + static int connect(unsigned int timeout_ms=15000); /** Disconnect
