@@ -173,7 +173,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
173173extern int lwip_ping_recv (int s , int * ttl );
174174extern 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 {
@@ -481,8 +481,13 @@ static err_t eth_netif_device_init(struct netif *netif)
481481rt_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 , "rtthread_%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 */
@@ -531,7 +538,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
531538 ipaddr .addr = inet_addr (RT_LWIP_IPADDR );
532539 gw .addr = inet_addr (RT_LWIP_GWADDR );
533540 netmask .addr = inet_addr (RT_LWIP_MSKADDR );
534- #else
541+ #else
535542 IP4_ADDR (& ipaddr , 0 , 0 , 0 , 0 );
536543 IP4_ADDR (& gw , 0 , 0 , 0 , 0 );
537544 IP4_ADDR (& netmask , 0 , 0 , 0 , 0 );
@@ -683,7 +690,7 @@ static void eth_rx_thread_entry(void* parameter)
683690 while (1 )
684691 {
685692 if (device -> eth_rx == RT_NULL ) break ;
686-
693+
687694 p = device -> eth_rx (& (device -> parent ));
688695 if (p != RT_NULL )
689696 {
@@ -706,9 +713,9 @@ static void eth_rx_thread_entry(void* parameter)
706713}
707714#endif
708715
709- /* this function does not need,
710- * use eth_system_device_init_private()
711- * call by lwip_system_init().
716+ /* this function does not need,
717+ * use eth_system_device_init_private()
718+ * call by lwip_system_init().
712719 */
713720int eth_system_device_init (void )
714721{
@@ -855,22 +862,22 @@ void list_if(void)
855862 ip6_addr_t * addr ;
856863 int addr_state ;
857864 int i ;
858-
865+
859866 addr = (ip6_addr_t * )& netif -> ip6_addr [0 ];
860867 addr_state = netif -> ip6_addr_state [0 ];
861-
862- 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 ),
863870 addr_state , ip6_addr_isvalid (addr_state )?"VALID" :"INVALID" );
864-
871+
865872 for (i = 1 ; i < LWIP_IPV6_NUM_ADDRESSES ; i ++ )
866873 {
867874 addr = (ip6_addr_t * )& netif -> ip6_addr [i ];
868875 addr_state = netif -> ip6_addr_state [i ];
869-
870- 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 ),
871878 addr_state , ip6_addr_isvalid (addr_state )?"VALID" :"INVALID" );
872879 }
873-
880+
874881 }
875882 rt_kprintf ("\r\n" );
876883#endif /* LWIP_IPV6 */
0 commit comments