فهرست منبع

[net][lwip] add personalized RT-Thread sign into lwip protocol stack as hostname.

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>
liuxianliang 5 سال پیش
والد
کامیت
3557d8f8a1

+ 8 - 0
components/net/lwip-1.4.1/src/lwipopts.h

@@ -499,6 +499,14 @@
 
 /* no read/write/close for socket */
 #define LWIP_POSIX_SOCKETS_IO_NAMES 0
+
+/**
+ * LWIP_NETIF_HOSTNAME==1: Support netif hostname
+ */
+#ifndef LWIP_NETIF_HOSTNAME
+#define LWIP_NETIF_HOSTNAME             1
+#endif
+
 #define LWIP_NETIF_API  1
 
 /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */

+ 13 - 1
components/net/lwip-1.4.1/src/netif/ethernetif.c

@@ -440,8 +440,13 @@ static err_t eth_netif_device_init(struct netif *netif)
 rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags)
 {
     struct netif* netif;
-
+#if LWIP_NETIF_HOSTNAME
+#define LWIP_HOSTNAME_LEN 16
+    char *hostname = RT_NULL;
+    netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
+#else
     netif = (struct netif*) rt_malloc (sizeof(struct netif));
+#endif
     if (netif == RT_NULL)
     {
         rt_kprintf("malloc netif failed\n");
@@ -476,6 +481,13 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
     netif->output		= etharp_output;
     netif->linkoutput	= ethernetif_linkoutput;
 
+#if LWIP_NETIF_HOSTNAME
+    /* Initialize interface hostname */
+	hostname = (char *)netif + sizeof(struct netif);
+    rt_sprintf(hostname, "RT-Thread_%02x%02x", name[0], name[1]);
+    netif->hostname = hostname;
+#endif /* LWIP_NETIF_HOSTNAME */
+
     /* if tcp thread has been started up, we add this netif to the system */
     if (rt_thread_find("tcpip") != RT_NULL)
     {

+ 7 - 0
components/net/lwip-2.0.2/src/lwipopts.h

@@ -531,6 +531,13 @@
 #define LWIP_TCP_KEEPALIVE              1
 #endif
 
+/**
+ * LWIP_NETIF_HOSTNAME==1: Support netif hostname
+ */
+#ifndef LWIP_NETIF_HOSTNAME
+#define LWIP_NETIF_HOSTNAME             1
+#endif
+
 /**
  * LWIP_NETIF_API==1: Support netif api (in netifapi.c)
  */

+ 9 - 2
components/net/lwip-2.0.2/src/netif/ethernetif.c

@@ -481,8 +481,13 @@ static err_t eth_netif_device_init(struct netif *netif)
 rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags)
 {
     struct netif* netif;
-
+#if LWIP_NETIF_HOSTNAME
+#define LWIP_HOSTNAME_LEN 16
+    char *hostname = RT_NULL;
+    netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
+#else
     netif = (struct netif*) rt_malloc (sizeof(struct netif));
+#endif
     if (netif == RT_NULL)
     {
         rt_kprintf("malloc netif failed\n");
@@ -519,7 +524,9 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
 
 #if LWIP_NETIF_HOSTNAME
     /* Initialize interface hostname */
-    netif->hostname = "rtthread";
+	hostname = (char *)netif + sizeof(struct netif);
+    rt_sprintf(hostname, "RT-Thread_%02x%02x", name[0], name[1]);
+    netif->hostname = hostname;
 #endif /* LWIP_NETIF_HOSTNAME */
 
     /* if tcp thread has been started up, we add this netif to the system */