]> granicus.if.org Git - esp-idf/commitdiff
tcpip_adapter: add get netif host name api
authorliuhan <liuhan@espressif.com>
Wed, 30 Nov 2016 08:44:31 +0000 (16:44 +0800)
committerWu Jian Gang <wujiangang@espressif.com>
Wed, 30 Nov 2016 09:41:19 +0000 (17:41 +0800)
components/tcpip_adapter/include/tcpip_adapter.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index f7063a8e17ee9e8f1190edbffb7e4ce5e0a68f64..b0de3ddcbcc252f5af26c01976c984d0f64c7915 100644 (file)
@@ -418,6 +418,18 @@ esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapt
  */
 esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname);
 
+/**
+ * @brief  Get the hostname from the interface
+ *
+ * @param[in]   tcpip_if: the interface which we will get the hostname
+ * @param[in]   hostname: the host name from the interfce
+ *
+ * @return ESP_OK:success
+ *         ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY:interface status error
+ *         ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS:parameter error
+ */
+esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname);
+
 #ifdef __cplusplus
 }
 #endif
index d9fda81d84ef6306a946fda9f3df5bb21ab16dab..4230cc39f0239b4cb80605c5a2f60bee0c8020a9 100644 (file)
@@ -702,4 +702,20 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
     }
 }
 
+esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname)
+{
+    struct netif *p_netif = NULL;
+    if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || hostname == NULL) {
+        return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
+    }
+
+    p_netif = esp_netif[tcpip_if];
+    if (p_netif != NULL) {
+        *hostname = p_netif->hostname;
+        return ESP_OK;
+    } else {
+        return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
+    }
+}
+
 #endif