| 
 
| 刚开始学STM32(stm32f407)和lwip,感觉各种头大,感觉回调函数没有被执行,先贴代码 
 void MyDNS(void)
 {
 char hostname[]="www.baidu.com";//需要解析的域名
 ip_addr_t *addr;                   //记录IP地址
 printf("hostname is %s\r\n",hostname);//在串口打印要解析的域名
 dns_gethostbyname(hostname,addr,my_found,NULL);//开始解析
 printf("dns is over\r\n");//在串口打印解析函数是否完成
 }
 
 
 两个打印函数在串口中都正常输出,说明dns_gethostbyname函数执行,但是在回调函数my_found中没有执行打印输出。my_found代码:
 static void my_found(const char *name, ip_addr_t *ipaddr, void *arg)
 {
 u8_t ip[4];
 myIP = *ipaddr;//保存IP
 printf("callback program is running\r\n");
 //分解IP
 ip[0] = myIP.addr>>24;
 ip[1] = myIP.addr>>16;
 ip[2] = myIP.addr>>8;
 ip[3] = myIP.addr;
 printf("%d.%d.%d.%d\r\n",ip[3], ip[2], ip[1], ip[0]); //打印IP
 printf("call back is running\r\n");
 }
 
 dns_gethostbyname函数在dns.c中定义,原函数代码如下:
 dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found,
 void *callback_arg)
 {
 u32_t ipaddr;
 /* not initialized or no valid server yet, or invalid addr pointer
 * or invalid hostname or invalid hostname length */
 if ((dns_pcb == NULL) || (addr == NULL) ||
 (!hostname) || (!hostname[0]) ||
 (strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
 return ERR_ARG;
 }
 
 #if LWIP_HAVE_LOOPIF
 if (strcmp(hostname, "localhost")==0) {
 ip_addr_set_loopback(addr);
 return ERR_OK;
 }
 #endif /* LWIP_HAVE_LOOPIF */
 
 /* host name already in octet notation? set ip addr and return ERR_OK */
 ipaddr = ipaddr_addr(hostname);
 if (ipaddr == IPADDR_NONE) {
 /* already have this address cached? */
 ipaddr = dns_lookup(hostname);
 }
 if (ipaddr != IPADDR_NONE) {
 ip4_addr_set_u32(addr, ipaddr);
 return ERR_OK;
 }
 
 /* queue query with specified callback */
 return dns_enqueue(hostname, found, callback_arg);
 }
 
 我想确定的是:
 1、我的回调函数写的是否正确?
 2、ip_addr_t *addr;                   //记录IP地址,这条代码,有的程序写成ip_addr_t addr;代码也能够正常编译,但是,我这样写的话,编译器报错,同一个编译器,他那样写就能够打印IP(但是打印的IP不正确),我这样写就报错,都是在lwip环境下。
 3、如果有高手能给分析一下有什么问题,那最好了
 
 | 
 |