Tool/software: Code Composer Studio
I'm trying to use the DNSGetHostByName(), but when I try to solve "google.com" the function returns 0 (NO ERROR) and the IP saved in the HOSTENT structure is 28.246.0.32, which is not a correct google IP. I tried other domains, like "ti.com", "www.ti.com", "www.google.com", "yahoo.com", but the IP solved is always in format: *.246.0.32, changing only the first number. I also tried some different DNS server addresses, like 8.8.8.8, 8.8.4.4, 1.1.1.1, but they all gave me the same results.
Here is my code:
char dominio[DOMAIN_SIZE];
memset(dominio, 0, DOMAIN_SIZE);
strcpy(dominio, "google.com");
fdOpenSession((void *) Task_self());
int ret = -1;
char buff[DNS_BUFFER_SIZE];
memset(buff, 0, DNS_BUFFER_SIZE);
// Shows the actual DNS server address
IPN dns;
CfgGetImmediate(0, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER, 1, 4, (uint8_t *)&dns );
dns = ntohl(dns);
System_printf("DNS address: ");
System_printf("%d.%d.%d.%d\n",
static_cast<uint8_t>((dns>>24)&0xFF),
static_cast<uint8_t>((dns>>16)&0xFF),
static_cast<uint8_t>((dns>>8)&0xFF),
static_cast<uint8_t>(dns&0xFF));
System_flush();
ret = DNSGetHostByName(dominio, (void*)buff, DNS_BUFFER_SIZE);
if(ret == 0)
{
HOSTENT *ht = (HOSTENT*)&buff[0];
IPN IPAddr = ht->h_addr[0];
IPAddr = ntohl(IPAddr);
System_printf("IP solved: %d.%d.%d.%d\n",
(uint8_t)(IPAddr>>24)&0xFF,
(uint8_t)(IPAddr>>16)&0xFF,
(uint8_t)(IPAddr>>8)&0xFF,
(uint8_t)IPAddr&0xFF);
}
else
{
System_printf("DNS error: %d\n", ret);
}
System_flush();
fdCloseSession((void *) Task_self());
Does anybody know what could be happening?
Thanks in advance,
Ronan