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.

EK-TM4C129EXL: How to add DNS server when using static IP httpget TI-RTOS example

Part Number: EK-TM4C129EXL

Tool/software:

Hello,

I'm modifying the 'httpget" TI-RTOS example in order to connect the dev kit to a local http server. I've been able to change the config to static IP via opening the .cfg file with XGCONF, but I haven't found a way to add a DNS server in the config file. Is there a way to do so?

Thanks!

  • Hi,

      You can add the DNS module like below. 

  • Hi Charles,

    That add a DNS server to the project. That's not what I'm looking to do. The problem that I'm facing is that, when I switch to static IP now the dev kit is not able to resolve the name of the http server. It seems that when a project used DHCP the DNS is assigned by default, but when static IP is used, it seems like the system does not have assigned a DNS server and therefore it get's a name resolution error. For this reason I need to let know the system what's the IP of the new DNS server. How can I do that?

  • Hi,

      I'm not sure. You might need to use getaddrinfo to find the IP address of www.example.com. I find this example using getaddrinfo that may help. 

    #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);
    }