Skip to content

Commit 3557d8f

Browse files
author
liuxianliang
committed
[net][lwip] add personalized RT-Thread sign into lwip protocol stack as hostname.
Signed-off-by: liuxianliang <[email protected]>
1 parent c73c349 commit 3557d8f

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

components/net/lwip-1.4.1/src/lwipopts.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@
499499

500500
/* no read/write/close for socket */
501501
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
502+
503+
/**
504+
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
505+
*/
506+
#ifndef LWIP_NETIF_HOSTNAME
507+
#define LWIP_NETIF_HOSTNAME 1
508+
#endif
509+
502510
#define LWIP_NETIF_API 1
503511

504512
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */

components/net/lwip-1.4.1/src/netif/ethernetif.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,13 @@ static err_t eth_netif_device_init(struct netif *netif)
440440
rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags)
441441
{
442442
struct netif* netif;
443-
443+
#if LWIP_NETIF_HOSTNAME
444+
#define LWIP_HOSTNAME_LEN 16
445+
char *hostname = RT_NULL;
446+
netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
447+
#else
444448
netif = (struct netif*) rt_malloc (sizeof(struct netif));
449+
#endif
445450
if (netif == RT_NULL)
446451
{
447452
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_
476481
netif->output = etharp_output;
477482
netif->linkoutput = ethernetif_linkoutput;
478483

484+
#if LWIP_NETIF_HOSTNAME
485+
/* Initialize interface hostname */
486+
hostname = (char *)netif + sizeof(struct netif);
487+
rt_sprintf(hostname, "RT-Thread_%02x%02x", name[0], name[1]);
488+
netif->hostname = hostname;
489+
#endif /* LWIP_NETIF_HOSTNAME */
490+
479491
/* if tcp thread has been started up, we add this netif to the system */
480492
if (rt_thread_find("tcpip") != RT_NULL)
481493
{

components/net/lwip-2.0.2/src/lwipopts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@
531531
#define LWIP_TCP_KEEPALIVE 1
532532
#endif
533533

534+
/**
535+
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
536+
*/
537+
#ifndef LWIP_NETIF_HOSTNAME
538+
#define LWIP_NETIF_HOSTNAME 1
539+
#endif
540+
534541
/**
535542
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
536543
*/

components/net/lwip-2.0.2/src/netif/ethernetif.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,13 @@ static err_t eth_netif_device_init(struct netif *netif)
481481
rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flags)
482482
{
483483
struct netif* netif;
484-
484+
#if LWIP_NETIF_HOSTNAME
485+
#define LWIP_HOSTNAME_LEN 16
486+
char *hostname = RT_NULL;
487+
netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
488+
#else
485489
netif = (struct netif*) rt_malloc (sizeof(struct netif));
490+
#endif
486491
if (netif == RT_NULL)
487492
{
488493
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_
519524

520525
#if LWIP_NETIF_HOSTNAME
521526
/* Initialize interface hostname */
522-
netif->hostname = "rtthread";
527+
hostname = (char *)netif + sizeof(struct netif);
528+
rt_sprintf(hostname, "RT-Thread_%02x%02x", name[0], name[1]);
529+
netif->hostname = hostname;
523530
#endif /* LWIP_NETIF_HOSTNAME */
524531

525532
/* if tcp thread has been started up, we add this netif to the system */

0 commit comments

Comments
 (0)