DNS under MQX 4.1

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,422件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 解決策
788件の閲覧回数
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 件の賞賛
返信
3 返答(返信)
788件の閲覧回数
oscargarciaabad
Contributor III

Hello Carlos Alberto and David,

Now, My code works fine!

Many thanks for your help!

Best regards,

Óscar.

0 件の賞賛
返信
788件の閲覧回数
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

789件の閲覧回数
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 件の賞賛
返信