Skip to content

Commit f9ef8c7

Browse files
author
liuxianliang
committed
[net][lwip] modified hostname, support lwIP 1.4.1 ,lwIP 2.0.2 and lwIP 2.1.2
Signed-off-by: liuxianliang <[email protected]>
1 parent a9cad2b commit f9ef8c7

File tree

5 files changed

+62
-53
lines changed

5 files changed

+62
-53
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@
264264
#endif
265265

266266
/*
267-
* You can re-define following setting in rtcofnig.h to overwrite the default
268-
* setting in the lwip opts.h
267+
* You can re-define following setting in rtcofnig.h to overwrite the default
268+
* setting in the lwip opts.h
269269
*/
270270
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
271271
// #define MEMP_NUM_NETBUF 2

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
165165
extern int lwip_ping_recv(int s, int *ttl);
166166
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
167167

168-
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
168+
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
169169
uint32_t timeout, struct netdev_ping_resp *ping_resp)
170170
{
171171
int s, ttl, recv_len, result = 0;
@@ -180,7 +180,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
180180
struct addrinfo hint, *res = RT_NULL;
181181
struct sockaddr_in *h = RT_NULL;
182182
struct in_addr ina;
183-
183+
184184
RT_ASSERT(netif);
185185
RT_ASSERT(host);
186186
RT_ASSERT(ping_resp);
@@ -199,7 +199,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
199199
return -RT_ERROR;
200200
}
201201
rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
202-
202+
203203
/* new a socket */
204204
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
205205
{
@@ -267,7 +267,7 @@ const struct netdev_ops lwip_netdev_ops =
267267
lwip_netdev_set_addr_info,
268268
#ifdef RT_LWIP_DNS
269269
lwip_netdev_set_dns_server,
270-
#else
270+
#else
271271
NULL,
272272
#endif /* RT_LWIP_DNS */
273273

@@ -315,7 +315,7 @@ static int netdev_add(struct netif *lwip_netif)
315315

316316
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
317317
result = netdev_register(netdev, name, (void *)lwip_netif);
318-
318+
319319
/* Update netdev info after registered */
320320
netdev->flags = lwip_netif->flags;
321321
netdev->mtu = lwip_netif->mtu;
@@ -325,7 +325,7 @@ static int netdev_add(struct netif *lwip_netif)
325325
netdev->ip_addr = lwip_netif->ip_addr;
326326
netdev->gw = lwip_netif->gw;
327327
netdev->netmask = lwip_netif->netmask;
328-
328+
329329
#ifdef RT_LWIP_DHCP
330330
netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
331331
#endif
@@ -484,7 +484,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
484484
#if LWIP_NETIF_HOSTNAME
485485
/* Initialize interface hostname */
486486
hostname = (char *)netif + sizeof(struct netif);
487-
rt_sprintf(hostname, "RTTHREAD_%02x%02x", name[0], name[1]);
487+
rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]);
488488
netif->hostname = hostname;
489489
#endif /* LWIP_NETIF_HOSTNAME */
490490

@@ -642,7 +642,7 @@ static void eth_rx_thread_entry(void* parameter)
642642
while (1)
643643
{
644644
if(device->eth_rx == RT_NULL) break;
645-
645+
646646
p = device->eth_rx(&(device->parent));
647647
if (p != RT_NULL)
648648
{

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
173173
extern int lwip_ping_recv(int s, int *ttl);
174174
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
175175

176-
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
176+
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
177177
uint32_t timeout, struct netdev_ping_resp *ping_resp)
178178
{
179179
int s, ttl, recv_len, result = 0;
@@ -188,7 +188,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
188188
struct addrinfo hint, *res = RT_NULL;
189189
struct sockaddr_in *h = RT_NULL;
190190
struct in_addr ina;
191-
191+
192192
RT_ASSERT(netif);
193193
RT_ASSERT(host);
194194
RT_ASSERT(ping_resp);
@@ -207,7 +207,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
207207
return -RT_ERROR;
208208
}
209209
rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
210-
210+
211211
/* new a socket */
212212
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
213213
{
@@ -275,7 +275,7 @@ const struct netdev_ops lwip_netdev_ops =
275275
lwip_netdev_set_addr_info,
276276
#ifdef RT_LWIP_DNS
277277
lwip_netdev_set_dns_server,
278-
#else
278+
#else
279279
NULL,
280280
#endif /* RT_LWIP_DNS */
281281

@@ -323,8 +323,8 @@ static int netdev_add(struct netif *lwip_netif)
323323

324324
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
325325
result = netdev_register(netdev, name, (void *)lwip_netif);
326-
327-
/* Update netdev info after registered */
326+
327+
/* Update netdev info after registered */
328328
netdev->flags = lwip_netif->flags;
329329
netdev->mtu = lwip_netif->mtu;
330330
netdev->ops = &lwip_netdev_ops;
@@ -333,7 +333,7 @@ static int netdev_add(struct netif *lwip_netif)
333333
netdev->ip_addr = lwip_netif->ip_addr;
334334
netdev->gw = lwip_netif->gw;
335335
netdev->netmask = lwip_netif->netmask;
336-
336+
337337
#ifdef RT_LWIP_DHCP
338338
netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
339339
#endif
@@ -412,7 +412,7 @@ static err_t eth_netif_device_init(struct netif *netif)
412412
/* network interface device register */
413413
netdev_add(netif);
414414
#endif /* RT_USING_NETDEV */
415-
415+
416416
ethif = (struct eth_device*)netif->state;
417417
if (ethif != RT_NULL)
418418
{
@@ -525,7 +525,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
525525
#if LWIP_NETIF_HOSTNAME
526526
/* Initialize interface hostname */
527527
hostname = (char *)netif + sizeof(struct netif);
528-
rt_sprintf(hostname, "RTTHREAD_%02x%02x", name[0], name[1]);
528+
rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]);
529529
netif->hostname = hostname;
530530
#endif /* LWIP_NETIF_HOSTNAME */
531531

@@ -538,7 +538,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
538538
ipaddr.addr = inet_addr(RT_LWIP_IPADDR);
539539
gw.addr = inet_addr(RT_LWIP_GWADDR);
540540
netmask.addr = inet_addr(RT_LWIP_MSKADDR);
541-
#else
541+
#else
542542
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
543543
IP4_ADDR(&gw, 0, 0, 0, 0);
544544
IP4_ADDR(&netmask, 0, 0, 0, 0);
@@ -690,7 +690,7 @@ static void eth_rx_thread_entry(void* parameter)
690690
while (1)
691691
{
692692
if(device->eth_rx == RT_NULL) break;
693-
693+
694694
p = device->eth_rx(&(device->parent));
695695
if (p != RT_NULL)
696696
{
@@ -713,9 +713,9 @@ static void eth_rx_thread_entry(void* parameter)
713713
}
714714
#endif
715715

716-
/* this function does not need,
717-
* use eth_system_device_init_private()
718-
* call by lwip_system_init().
716+
/* this function does not need,
717+
* use eth_system_device_init_private()
718+
* call by lwip_system_init().
719719
*/
720720
int eth_system_device_init(void)
721721
{
@@ -862,22 +862,22 @@ void list_if(void)
862862
ip6_addr_t *addr;
863863
int addr_state;
864864
int i;
865-
865+
866866
addr = (ip6_addr_t *)&netif->ip6_addr[0];
867867
addr_state = netif->ip6_addr_state[0];
868-
869-
rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr),
868+
869+
rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr),
870870
addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID");
871-
871+
872872
for(i=1; i<LWIP_IPV6_NUM_ADDRESSES; i++)
873873
{
874874
addr = (ip6_addr_t *)&netif->ip6_addr[i];
875875
addr_state = netif->ip6_addr_state[i];
876-
877-
rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr),
876+
877+
rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr),
878878
addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID");
879879
}
880-
880+
881881
}
882882
rt_kprintf("\r\n");
883883
#endif /* LWIP_IPV6 */

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@
538538
#define LWIP_TCP_KEEPALIVE 1
539539
#endif
540540

541+
/**
542+
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
543+
*/
544+
#ifndef LWIP_NETIF_HOSTNAME
545+
#define LWIP_NETIF_HOSTNAME 1
546+
#endif
547+
541548
/**
542549
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
543550
*/

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
174174
extern int lwip_ping_recv(int s, int *ttl);
175175
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
176176

177-
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
177+
int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
178178
uint32_t timeout, struct netdev_ping_resp *ping_resp)
179179
{
180180
int s, ttl, recv_len, result = 0;
@@ -189,7 +189,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
189189
struct addrinfo hint, *res = RT_NULL;
190190
struct sockaddr_in *h = RT_NULL;
191191
struct in_addr ina;
192-
192+
193193
RT_ASSERT(netif);
194194
RT_ASSERT(host);
195195
RT_ASSERT(ping_resp);
@@ -208,7 +208,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len,
208208
return -RT_ERROR;
209209
}
210210
rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t));
211-
211+
212212
/* new a socket */
213213
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0)
214214
{
@@ -276,7 +276,7 @@ const struct netdev_ops lwip_netdev_ops =
276276
lwip_netdev_set_addr_info,
277277
#ifdef RT_LWIP_DNS
278278
lwip_netdev_set_dns_server,
279-
#else
279+
#else
280280
NULL,
281281
#endif /* RT_LWIP_DNS */
282282

@@ -315,7 +315,7 @@ static int netdev_add(struct netif *lwip_netif)
315315
{
316316
return -ERR_IF;
317317
}
318-
318+
319319
#ifdef SAL_USING_LWIP
320320
extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev);
321321
/* set the lwIP network interface device protocol family information */
@@ -324,7 +324,7 @@ static int netdev_add(struct netif *lwip_netif)
324324

325325
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
326326
result = netdev_register(netdev, name, (void *)lwip_netif);
327-
327+
328328
/* Update netdev info after registered */
329329
netdev->flags = lwip_netif->flags;
330330
netdev->mtu = lwip_netif->mtu;
@@ -367,7 +367,7 @@ static int netdev_flags_sync(struct netif *lwip_netif)
367367
{
368368
return -ERR_IF;
369369
}
370-
370+
371371
netdev->mtu = lwip_netif->mtu;
372372
netdev->flags |= lwip_netif->flags;
373373

@@ -430,7 +430,7 @@ static err_t eth_netif_device_init(struct netif *netif)
430430
/* copy device flags to netif flags */
431431
netif->flags = (ethif->flags & 0xff);
432432
netif->mtu = ETHERNET_MTU;
433-
433+
434434
/* set output */
435435
netif->output = etharp_output;
436436

@@ -518,13 +518,15 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
518518

519519
/* set linkoutput */
520520
netif->linkoutput = ethernetif_linkoutput;
521-
521+
522522
/* get hardware MAC address */
523523
rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
524524

525525
#if LWIP_NETIF_HOSTNAME
526526
/* Initialize interface hostname */
527-
netif->hostname = "rtthread";
527+
hostname = (char *)netif + sizeof(struct netif);
528+
rt_sprintf(hostname, "rtthread_%02x%02x", name[0], name[1]);
529+
netif->hostname = hostname;
528530
#endif /* LWIP_NETIF_HOSTNAME */
529531

530532
/* if tcp thread has been started up, we add this netif to the system */
@@ -536,7 +538,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
536538
ipaddr.addr = inet_addr(RT_LWIP_IPADDR);
537539
gw.addr = inet_addr(RT_LWIP_GWADDR);
538540
netmask.addr = inet_addr(RT_LWIP_MSKADDR);
539-
#else
541+
#else
540542
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
541543
IP4_ADDR(&gw, 0, 0, 0, 0);
542544
IP4_ADDR(&netmask, 0, 0, 0, 0);
@@ -688,7 +690,7 @@ static void eth_rx_thread_entry(void* parameter)
688690
while (1)
689691
{
690692
if(device->eth_rx == RT_NULL) break;
691-
693+
692694
p = device->eth_rx(&(device->parent));
693695
if (p != RT_NULL)
694696
{
@@ -711,9 +713,9 @@ static void eth_rx_thread_entry(void* parameter)
711713
}
712714
#endif
713715

714-
/* this function does not need,
715-
* use eth_system_device_init_private()
716-
* call by lwip_system_init().
716+
/* this function does not need,
717+
* use eth_system_device_init_private()
718+
* call by lwip_system_init().
717719
*/
718720
int eth_system_device_init(void)
719721
{
@@ -860,22 +862,22 @@ void list_if(void)
860862
ip6_addr_t *addr;
861863
int addr_state;
862864
int i;
863-
865+
864866
addr = (ip6_addr_t *)&netif->ip6_addr[0];
865867
addr_state = netif->ip6_addr_state[0];
866-
867-
rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr),
868+
869+
rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr),
868870
addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID");
869-
871+
870872
for(i=1; i<LWIP_IPV6_NUM_ADDRESSES; i++)
871873
{
872874
addr = (ip6_addr_t *)&netif->ip6_addr[i];
873875
addr_state = netif->ip6_addr_state[i];
874-
875-
rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr),
876+
877+
rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr),
876878
addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID");
877879
}
878-
880+
879881
}
880882
rt_kprintf("\r\n");
881883
#endif /* LWIP_IPV6 */

0 commit comments

Comments
 (0)