summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorliuxianliang <[email protected]>2019-12-18 14:20:55 +0800
committerliuxianliang <[email protected]>2019-12-18 14:20:55 +0800
commit3557d8f8a18e3600584ac2d3ebc36bc54dfdab41 (patch)
tree67de9cddb7dc48334b707fc8d42671bee8cba88f /components
parentc73c349113731567fe7d35621a0c254e2050a029 (diff)
[net][lwip] add personalized RT-Thread sign into lwip protocol stack as hostname.
Signed-off-by: liuxianliang <[email protected]>
Diffstat (limited to 'components')
-rw-r--r--components/net/lwip-1.4.1/src/lwipopts.h8
-rw-r--r--components/net/lwip-1.4.1/src/netif/ethernetif.c14
-rw-r--r--components/net/lwip-2.0.2/src/lwipopts.h7
-rw-r--r--components/net/lwip-2.0.2/src/netif/ethernetif.c11
4 files changed, 37 insertions, 3 deletions
diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h
index dd59acd589..598c3262a6 100644
--- a/components/net/lwip-1.4.1/src/lwipopts.h
+++ b/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. */
diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c
index 9d8fa650a4..70dd9c00d0 100644
--- a/components/net/lwip-1.4.1/src/netif/ethernetif.c
+++ b/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)
{
diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h
index f90ef1a825..c53863e1ab 100644
--- a/components/net/lwip-2.0.2/src/lwipopts.h
+++ b/components/net/lwip-2.0.2/src/lwipopts.h
@@ -532,6 +532,13 @@
#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)
*/
#ifndef LWIP_NETIF_API
diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c
index a7bed3065f..87aecdb58b 100644
--- a/components/net/lwip-2.0.2/src/netif/ethernetif.c
+++ b/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 */