请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:EK-TM4C129EXL 工具与软件:
您好!
我正在修改'HttpGet"TI-RTOS 示例、以便将开发套件连接到本地 http 服务器。 我已经能够通过使用 XGCONF 打开.cfg 文件将配置更改为静态 IP、但我没有找到在配置文件中添加 DNS 服务器的方法。 是否有办法做到这一点?
谢谢!
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.
工具与软件:
您好!
我正在修改'HttpGet"TI-RTOS 示例、以便将开发套件连接到本地 http 服务器。 我已经能够通过使用 XGCONF 打开.cfg 文件将配置更改为静态 IP、但我没有找到在配置文件中添加 DNS 服务器的方法。 是否有办法做到这一点?
谢谢!
尊敬的 Charles:
向项目添加 DNS 服务器的用户。 这不是我要做的。 我面临的问题是、当我切换到静态 IP 时、开发套件无法解析 http 服务器的名称。 似乎当项目使用 DHCP 时、DNS 是默认分配的、但当使用静态 IP 时、系统似乎没有分配 DNS 服务器、因此它得到一个名称解析错误。 因此、我需要让系统知道新 DNS 服务器的 IP 是什么。 我怎么能做到这一点?
您好!
我不确定。 您可能需要使用 getaddrinfo 来查找 www.example.com 的 IP 地址。 我使用 getaddrinfo 找到这个示例可能会有所帮助。
#include <string.h>
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/GPIO.h>
#include <dns.h>
/* Example/Board Header file */
#include "Board.h"
#define DNSHANDLERSTACK 2048
#define NUM_HOST 4
#define INET_ADDRSTRLEN 16
static char strIp[INET_ADDRSTRLEN];
/*
* List of host names to resolve by DNS
*/
const char *hostname[NUM_HOST] = { "pool.ntp.org", "www.google.com", "api.openweathermap.org", "www.ti.com" };
/*
* ======== dnsWorker ========
* Task to request DNS service
*/
Void dnsWorker(UArg arg0, UArg arg1)
{
struct addrinfo *server_data = NULL;
int result;
int i;
for (i=0;i<NUM_HOST;i++)
{
System_printf("!!!!!!!!!!\n", result);
System_flush();
/*
* Given the host name, which identify a Internet host, getaddrinfo
* returns one or more addrinfo structure, each of which contains
* an Internet address that can be specified in a call to bind or
* connect
*/
result = getaddrinfo(hostname[i], "0", NULL, &server_data);
if (result == 0 && server_data != NULL)
{
struct sockaddr addr = *(server_data->ai_addr);
/*
* convert IP address structure to string format
*/
inet_ntop(AF_INET, &((struct sockaddr_in *)&addr)->sin_addr, strIp, INET_ADDRSTRLEN);
System_printf("HOSTNAME: %s\tResolved address:%s\n", hostname[i],strIp);
System_flush();
freeaddrinfo(server_data);
server_data = NULL;
}
Task_sleep(1000); // Sleep for 1 seconds
}
}
/*
* ======== dnsHooks ========
* Creates new Task to request DNS service.
*/
Void dnsHooks(UArg arg0, UArg arg1)
{
Task_Handle taskHandle;
Task_Params taskParams;
Error_Block eb;
/* Init the Error_Block */
Error_init(&eb);
/* Initialize the defaults and set the parameters. */
Task_Params_init(&taskParams);
taskParams.stackSize = DNSHANDLERSTACK;
taskParams.priority = 1;
taskHandle = Task_create((Task_FuncPtr)dnsWorker, &taskParams, &eb);
if (taskHandle == NULL) {
System_printf("Error: Failed to create new Task\n");
}
}
/*
* ======== main ========
*/
int main(void)
{
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initEMAC();
System_printf("Starting the DNS request example\nSystem provider is set to "
"SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}