Hostname can now be set

Dependencies:   Socket lwip-eth lwip-sys lwip

Dependents:   GolemTemperaturCheck

Fork of EthernetInterface by mbed official

Files at this revision

API Documentation at this revision

Comitter:
wolfsberger
Date:
Tue May 03 08:29:03 2016 +0000
Parent:
52:f81b90d9a441
Commit message:
Hostname can now be specified.

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
lwip-eth.lib Show annotated file Show diff for this revision Revisions of this file
lwip.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Fri Apr 29 01:16:12 2016 +0100
+++ b/EthernetInterface.cpp	Tue May 03 08:29:03 2016 +0000
@@ -59,7 +59,7 @@
     }
 }
 
-static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
+static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, char * hostname) {
     tcpip_init(tcpip_init_done, NULL);
     tcpip_inited.wait();
     
@@ -67,6 +67,11 @@
     netif_add(&netif, ipaddr, netmask, gw, NULL, eth_arch_enetif_init, tcpip_input);
     netif_set_default(&netif);
     
+    if (hostname != NULL)
+    {
+        netif.hostname = hostname;
+    }
+    
     netif_set_link_callback  (&netif, netif_link_callback);
     netif_set_status_callback(&netif, netif_status_callback);
 }
@@ -82,14 +87,29 @@
 #endif
 }
 
-int EthernetInterface::init() {
+int EthernetInterface::init(char * hostname) {
     use_dhcp = true;
     set_mac_address();
-    init_netif(NULL, NULL, NULL);
+    init_netif(NULL, NULL, NULL, hostname);
     return 0;
 }
 
-int EthernetInterface::init(const char* ip, const char* mask, const char* gateway) {
+int EthernetInterface::init(const char* ip, const char* mask, const char* gateway, char * hostname) {
+    use_dhcp = false;
+    
+    set_mac_address();
+    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);
+    init_netif(&ip_n, &mask_n, &gateway_n, hostname);
+    
+    return 0;
+}
+
+/*int EthernetInterface::init(const char* ip, const char* mask, const char* gateway) {
     use_dhcp = false;
     
     set_mac_address();
@@ -102,7 +122,7 @@
     init_netif(&ip_n, &mask_n, &gateway_n);
     
     return 0;
-}
+}*/
 
 int EthernetInterface::connect(unsigned int timeout_ms) {
     eth_arch_enable_interrupts();
--- a/EthernetInterface.h	Fri Apr 29 01:16:12 2016 +0100
+++ b/EthernetInterface.h	Tue May 03 08:29:03 2016 +0000
@@ -34,9 +34,10 @@
 public:
   /** Initialize the interface with DHCP.
   * Initialize the interface and configure it to use DHCP (no connection at this point).
+  * \param hostname the hostname.
   * \return 0 on success, a negative number on failure
   */
-  static int init(); //With DHCP
+  static int init(char* hostname = NULL); //With DHCP
 
   /** Initialize the interface with a static IP address.
   * Initialize the interface and configure it with the following static configuration (no connection at this point).
@@ -45,7 +46,17 @@
   * \param gateway the gateway to use
   * \return 0 on success, a negative number on failure
   */
-  static int init(const char* ip, const char* mask, const char* gateway);
+  //static int init(const char* ip, const char* mask, const char* gateway);
+  
+  /** Initialize the interface with a static IP address.
+  * Initialize 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
+  * \param hostname the hostname of the device
+  * \return 0 on success, a negative number on failure
+  */
+  static int init(const char* ip, const char* mask, const char* gateway, char* hostname = NULL);
 
   /** Connect
   * Bring the interface up, start DHCP if needed.
--- a/lwip-eth.lib	Fri Apr 29 01:16:12 2016 +0100
+++ b/lwip-eth.lib	Tue May 03 08:29:03 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip-eth/#4380f0749039
+http://mbed.org/users/mbed_official/code/lwip-eth/#da93f0f73711
--- a/lwip.lib	Fri Apr 29 01:16:12 2016 +0100
+++ b/lwip.lib	Tue May 03 08:29:03 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip/#1046f8be4d44
+http://mbed.org/users/mbed_official/code/lwip/#08f08bfc3f3d