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.

What would cause sl_NetAppDnsGetHostByName() to return SL_NET_APP_DNS_INTERNAL_8 (-172) only when called from a linked-in library?

Other Parts Discussed in Thread: CC3100, SEGGER

I'm using a CC3100 SimpleLink and FreeRtos on an STM32F4 part and am trying to move my code into a library.

If I setup the OS, start  SinpleLink, connect to my AP and wait a little while, I can call sl_NetAppDnsGetHostByName() and get proper name resolution all day long.

If I call a function libgetname() which is in a library,  sl_NetAppDnsGetHostByName() returns with SL_NET_APP_DNS_INTERNAL_8 all day long.

I've put a breakpoint at the entry to sl_NetAppDnsGetHostByName() and I can see that the exact same parameters are in R0-3, so I'm confised as to what's going on.

function maingetname() and libgetname() are identical. One is in the main project and one is in a library that was compiled using a different workspace/project.

mygetname()/libgetname() {

  char bname[] = "google.com";
  int retval;
  long uiIP;

  retval = sl_NetAppDnsGetHostByName(copied_name, sizeof( bname ), (unsigned long*) &uiIP, SL_AF_INET );
  printf("retval = %d IP = 0x%08x\n",retval,uiIP);

}

The library is built with the same processor target as the main application.

My process is as follows:

1) open the workspace/project for the library project.

2) Build the library.

3) Open the workspace/project for the main application

4) Build and link in the library from the library project  with Options->Linker->Library set toC:\cygwin64\home\myname\libmylib-v3\proj\IAR\libxively\Debug\Exe\libmylib.a

5) Download and debug using a IAR (Segger) Jlink

I figure I've got something misconfigured in the library build, but I just can't seem to find it.

  • Hi Alan,

    Can you please check from the debugger if the values (string / string length) are passed correctly? The debugger would show the correct string, but some times the string may not be null terminated, resulting in a varying string length. Can you please check if this is the case her?

    Regards,
    Raghavendra
  • Thanks for the reply.

    I've put a breakpoint at the entry to sl_NetAppDnsGetHostByName() and I can see that the exact same parameters are in R0-3,.

    Also, you can see from the code example I included in my problem description that I am using a NULL-terminated string.

    Thanks for the idea, but that's not the issue.

  • Hi Alan,

    Was not sure if copied_name had the same contents as that of bname. I hope copied_name has the right content.
    We will check this and get back to you.

    Regards,
    Raghavendra
  • I see.

    That was a mistake in my copying code to create the example.
    My mistake. Thanks for helping me clarify the issue.

    The actual code is as follows:

    mygetname()/libgetname() {

    char bname[] = "google.com";
    int retval;
    long uiIP;

    retval = sl_NetAppDnsGetHostByName(bname, sizeof( bname ), (unsigned long*) &uiIP, SL_AF_INET );
    printf("retval = %d IP = 0x%08x\n",retval,uiIP);

    }
  • Previously, I had one library compiled with Variable Length Arrays enabled and one without, so I rebuilt everything with VLS not enabled and I have the same issue.

    I also tried another experiment that shows that the issue is when the call to sl_NetAppDnsGetHostByName() is in my library wather than in a function compiled in this project:

    ------InTHisProject functions:--------

    a() {
    b();
    }

    c() {char bname[] = "google.com";
    int retval;
    long uiIP;

    retval = sl_NetAppDnsGetHostByName(bname, sizeof( bname ), (unsigned long*) &uiIP, SL_AF_INET );
    printf("retval = %d IP = 0x%08x\n",retval,uiIP);
    }

    --------InTheLibnraryFunctions:--------
    b() {
    c();
    }

    This results in a working return value fromsl_NetAppDnsGetHostByName().
    So it looks like somehow calling sl_NetAppDnsGetHostByName() from my library is resulting in the error being returned.
  • Could you please check the CC3100 source and let me know under what conditions it returns SL_NET_APP_DNS_INTERNAL_8 (-172)?
    That may help me find my mistake.
  • I think the problem is sizeof(bname) will return 11 and there are only 10 chars (the string is really "google.com\0").

    I think error code -172 that the DNS does not known name. At least that's the code I get back when I pass in "ABC"
  • That may be the problem. I've worked around this issue, so I can't test it at this time.

    Looking at examples, I do see that they use strlen() instead of sizeof().

    Thank you for the hint.

    #include <string.h>

    int main () {

      char bname[] = "google.com";

      printf("sizeof %s = %lu\n",bname,sizeof(bname));

      printf("strlen %s = %lu\n",bname,strlen(bname));

    }

    ~ ./a

    sizeof google.com = 11

    strlen google.com = 10