DNS under MQX 4.1

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DNS under MQX 4.1

Jump to solution
1,468 Views
oscargarciaabad
Contributor III

Hello all,

I'm running MQX 4.1 on a TWR-K60F120M. I want to translate www.google.com to an IP address. To do that I'm enabling DNS. I want to make the DNS request to my router (wich is located at 172.16.0.1 --> 0xA1160001).

I define DNS parameters under source/if/dnshost.c the following way:

char DNS_Local_network_name[] = ".";

uint32_t DNS_CACHE_NAME_LIMIT = 0;

char DNS_Local_server_name[] = "";

DNS_SLIST_STRUCT DNS_Local_server_list[] =

   {{DNS_Local_server_name, 0, 0xAC160001, 0, 0, 0, 0,

     0, DNS_A, DNS_IN }};

DNS_SLIST_STRUCT      *DNS_First_Local_server = &DNS_Local_server_list[0];

Then I call DNS_init() in my code.

After that I call gethostbyname() as you can see next:

HOSTENT_STRUCT_PTR CPTServer;

printf("Initializing DNS service...");

if(DNS_init() != RTCS_OK) {

  printf("KO\n");

  _task_block();

}

printf("OK\n");

printf("Resolving google.com");

CPTServer = gethostbyname("www.google.com.");

if(CPTServer == NULL) {

       printf("KO\n");

       _task_block();

}

printf("OK\n");

The code is running with no problems. But, how can I extract the IP from CPTServer?

Thanks in advance.

Óscar.

Labels (1)
0 Kudos
Reply
1 Solution
834 Views
DavidS
NXP Employee
NXP Employee

Carlos's information very good.

I have implemented the below for my DNS example:

       host = gethostbyname(string);        if (host != NULL) {         name = host->h_name;         alias1 = host->h_aliases[0];         alias2 = host->h_aliases[1];         type = host->h_addrtype;         length = host->h_length;         ip = *(uint_32_ptr)host->h_addr_list[0];         printf ("  %d.%d.%d.%d\n", IPBYTES(ip));

       }          else {         printf("\nNo IP address found for given URL....try again please.\n");        }

Regards,

David

View solution in original post

0 Kudos
Reply
3 Replies
834 Views
oscargarciaabad
Contributor III

Hello Carlos Alberto and David,

Now, My code works fine!

Many thanks for your help!

Best regards,

Óscar.

0 Kudos
Reply
834 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Oscar,

I have recently used RTCS shell example:

C:\Freescale\Freescale_MQX_4_1\rtcs\examples\shell

The _README.txt file is very clear and it explains all the example services including DNS. With this example I was able to solve www.google.com IP address.

I hope it helps.

Regards,

Carlos

835 Views
DavidS
NXP Employee
NXP Employee

Carlos's information very good.

I have implemented the below for my DNS example:

       host = gethostbyname(string);        if (host != NULL) {         name = host->h_name;         alias1 = host->h_aliases[0];         alias2 = host->h_aliases[1];         type = host->h_addrtype;         length = host->h_length;         ip = *(uint_32_ptr)host->h_addr_list[0];         printf ("  %d.%d.%d.%d\n", IPBYTES(ip));

       }          else {         printf("\nNo IP address found for given URL....try again please.\n");        }

Regards,

David

0 Kudos
Reply