This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C例程如何使用DNS.C中的函数,开启了LWIP_NETCONN宏之后就报错,好像和NO_SYS宏有关,请教一下如何解决

Other Parts Discussed in Thread: EK-TM4C1294XL

我这边使用了tm4c1294ncpdt-master\tm4c1294ncpdt-master\sw-tm4c-2.1.1.71\examples\boards\ek-tm4c1294xl下的enet_s2e例程,目前开启LWIP_NETCONN宏之后会报以下错误,而在我查看代码的时候发现应该已经是定义了,请大牛们帮忙看下这是哪边的问题

  • 若是可以的话,请您给出您的 lwipopts.h 文件

    在lwip有3种sockets : 1. Raw sockets, netconn interface 以及 bsd-sockets. 您现在是想使用哪一个,实现什么功能呢?
  • 另外有相关文档您可以参考一下

    www.ti.com/.../spma072.pdf
  • 你好,这是我的lwipopts.h文件,我想调用的是api_lib.c中的netconn_gethostbyname()接口,好像需要开NETCONN这个宏,但是开了又报之前的错lwipopts.h

  • 关于netconn_gethostbyname的定义如下

    #if LWIP_DNS
    /**
     * Execute a DNS query, only one IP address is returned
     *
     * @param name a string representation of the DNS host name to query
     * @param addr a preallocated struct ip_addr where to store the resolved IP address
     * @return ERR_OK: resolving succeeded
     *         ERR_MEM: memory error, try again later
     *         ERR_ARG: dns client not initialized or invalid hostname
     *         ERR_VAL: dns server response was invalid
     */
    err_t
    netconn_gethostbyname(const char *name, struct ip_addr *addr)
    {
      struct dns_api_msg msg;
      err_t err;
      sys_sem_t sem;
    
      LWIP_ERROR("netconn_gethostbyname: invalid name", (name != NULL), return ERR_ARG;);
      LWIP_ERROR("netconn_gethostbyname: invalid addr", (addr != NULL), return ERR_ARG;);
    
      sem = sys_sem_new(0);
      if (sem == SYS_SEM_NULL) {
        return ERR_MEM;
      }
    
      msg.name = name;
      msg.addr = addr;
      msg.err = &err;
      msg.sem = sem;
    
      tcpip_callback(do_gethostbyname, &msg);
      sys_sem_wait(sem);
      sys_sem_free(sem);
    
      return err;
    }
    #endif /* LWIP_DNS*/

    该函数提供了从域名查询其IP地址的功能

    按照我的理解,在调用此函数之前应该

    1. 在lwipopts.h中打开DNS:

    #define LWIP_UDP 1

    2. 调用函数dns_init()创建dns_pcb
    void dns_init()
    该函数位置在lwip/src/core/dns.c中,负责初始化解析器,设置UDP pcb并且配置默认的DNS服务器

    我对这个网络协议也不是太了解,您可以试一下。还是不行的话,建议那您去E2E https://e2e.ti.com/support/microcontrollers/other/f/908 去问问

    TM4C这方面的资料比较少