嵌入式技术论坛
直播中

ss

8年用户 8762经验值
擅长:电源/新能源 制造/封装 RF/无线
私信 关注
[问答]

请问一下LwIP为什么无法获取host地址呢

调用这个函数不成功。





主要是gethostbyname这个函数通不过。
应当没有抓到包吧。第一次用WiresharkPortable,还不会看.呵呵







回帖(5)

ss

2022-3-23 09:42:15
  调试发现是下面的函数中通不过

  struct sys_timeouts *sys_arch_timeouts(void)

  {

  rt_thread_t self = rt_thread_self();

  struct lwip_thread* lwip_th = (struct lwip_thread*)self-》user_data;

  if (lwip_th != RT_NULL)

  {

  RT_ASSERT(lwip_th-》magic == LWIP_THREAD_MAGIC); ------这里通不过。

  return &(lwip_th-》timeouts);

  }

  return RT_NULL;

  }

  我的配置如下:

  /* ip address of target */

  #define RT_LWIP_IPADDR0 192

  #define RT_LWIP_IPADDR1 168

  #define RT_LWIP_IPADDR2 1

  #define RT_LWIP_IPADDR3 15

  /* gateway address of target */

  #define RT_LWIP_GWADDR0 192

  #define RT_LWIP_GWADDR1 168

  #define RT_LWIP_GWADDR2 1

  #define RT_LWIP_GWADDR3 1

  /* mask address of target */

  #define RT_LWIP_MSKADDR0 255

  #define RT_LWIP_MSKADDR1 255

  #define RT_LWIP_MSKADDR2 255

  #define RT_LWIP_MSKADDR3 0

  为什么上面的图中的目标地址是192.168.1.255呢?(我这样配置不是设定开发板的IP为192.168.15吗?)

  是不是没ping通啊,但是我的开发板上的网口灯是亮的。而且PC机的网络图标也由断开变为连接。
举报

ss

2022-3-23 09:42:31
gethostbyname怎么传了一个ip地址进去了。
另外你确定是在RT_ASSERT(lwip_th->magic == LWIP_THREAD_MAGIC);这个地方卡住了么
举报

ss

2022-3-23 09:42:45
我单步调试很多次,都是这里RT_ASSERT(lwip_th->magic == LWIP_THREAD_MAGIC);卡住了
举报

ss

2022-3-23 09:42:57
通常ip地址是不需要再进行域名解析的(gethostbyname),域名才需要进行解析。

不过传一个ip地址进去也不应该会卡在这个地方,得看看gethostbyname中调用了什么API,按理不应该在使用lwip timer的方式。
举报

ss

2022-3-23 09:43:48
今天用FinSH试了UDPClient,发现可以发数据出去.

但是如果放到GUI线程去执行UDPClient,则不能发数据出去.同样是无法获取到host.我怀疑是GUI和LwIP有资源方面的冲突.

测试代码如下:

#include "demo_view.h"

#include   

#include

static void TCP_Client(struct rtgui_widget* widget, rtgui_event_t* event)

{

   tcpclient("192.168.1.2",80);  

   /*tcpclient(");

   tcpclient("192.168.1.2",139);*/

}

static void UDP_Client(struct rtgui_widget* widget, rtgui_event_t* event)

{

   udpclient("192.168.1.2",138,2);  

}

static void TCP_Server(struct rtgui_widget* widget, rtgui_event_t* event)

{  

   tcpserv(RT_NULL);  

}

static void UDP_Server(struct rtgui_widget* widget, rtgui_event_t* event)

{

   udpserv(RT_NULL);  

}

rtgui_view_t *test_lwip(rtgui_workbench_t* workbench)

{

   rtgui_view_t *view1;

   rtgui_button_t *button;   

   rtgui_rect_t widget_rect;

   view1 = demo_view(workbench, "test");

   demo_view_get_rect(view1, &widget_rect);

   widget_rect.x1 = 5;

   widget_rect.x2 = widget_rect.x1 + 50;

   widget_rect.y1 = 170;

   widget_rect.y2 = widget_rect.y1 + 20;

   button = rtgui_button_create("TCPClient");

   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);

   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));

   rtgui_button_set_onbutton(button, TCP_Client);

   widget_rect.x1 = widget_rect.x2 + 10;

   widget_rect.x2 += 50;

   button = rtgui_button_create("UDPClient");

   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);

   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));

   rtgui_button_set_onbutton(button, UDP_Client);

   widget_rect.x1 = widget_rect.x2 + 10;

   widget_rect.x2 += 50;

   button = rtgui_button_create("TCPServer");

   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);

   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));

   rtgui_button_set_onbutton(button, TCP_Server);  

    widget_rect.x1 = widget_rect.x2 + 10;

   widget_rect.x2 += 50;

   button = rtgui_button_create("UDPServer");

   rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);

   rtgui_container_add_child(RTGUI_CONTAINER(view1), RTGUI_WIDGET(button));

   rtgui_button_set_onbutton(button, UDP_Server);        

   return view1;

}
举报

更多回帖

发帖
×
20
完善资料,
赚取积分