Cannot Resolve Host with libcurl

Hi everyone,

I’m having a strange issue with the use of libcurl. I’m attempting to connect to mobile data, then use libcurl to get the contents of a website. However, I always receive the error:

curl_easy_perform() failed: Couldn't resolve host name

I’m using the Modem Data Control service to connect to data. My code is as follows (somewhat truncated, error handling and such excluded):

le_mdc_ConnectService();
defaultModemProfile = le_mdc_GetProfile(LE_MDC_DEFAULT_PROFILE);
le_mdc_SetAPN(defaultModemProfile, "att.mvno");
le_mdc_SetPDP(defaultModemProfile, LE_MDC_PDP_IPV4);
le_mdc_ConState_t state;
le_mdc_GetSessionState(defaultModemProfile, &state);
le_mdc_StartSession(defaultModemProfile);

The connection seems to work fine using this logic. Then, via libcurl, I’m doing the following:

curl_global_init(CURL_GLOBAL_ALL);
CURL *myHandle;
CURLcode result;
myHandle = curl_easy_init();
char *destUrl = "http://example.com";
curl_easy_setopt(myHandle, CURLOPT_URL, destUrl);
curl_easy_setopt(myHandle, CURLOPT_HTTPGET, 1);
curl_easy_setopt(myHandle, CURLOPT_FOLLOWLOCATION, 1L);
result = curl_easy_perform(myHandle);
curl_easy_cleanup(myHandle);

However, it always returns the Couldn't resolve host name error.

Interestingly enough, if I comment out the above code (so my application isn’t establishing the connection), and instead use the cm data connect command through SSH, then run my application, libcurl returns the page with no issues.

Based on that, I’m thinking maybe this is some sort of DNS issue, although I can’t say for sure. Is there some means by which I’m supposed to configuring DNS through the Modem Data Control service?

Thanks much in advance!

  • Which module are you running this code on?
  • Which modem firmware are you running?
  • Which Legato framework version are you running?
  • Is the app that uses libcurl sandboxed?

Hi @dfrey

Here’s my setup:
Board: MangOH Red
Device: WP8548
Device Firmware: SWI9X15Y_07.12.09.00
Legato Version: 16.10.3

The app is not sandboxed (I have sandboxed:false in my adef file).

I’ve been diagnosing this problem the past few days, and I’ve found the source of the issue (albeit not a solution). For some reason, when I establish a data connection through my application, the routing table fails to populate correctly.

Here’s the routing table (via "route -n") when I connect to data via "cm data connect" in SSH:
routing_ssh

Meanwhile, here it is when I connect through my application:
routing_app

Notice how the entry for the gateway is completely missing. Interestingly enough, however, if I run cm data info on both instances, a gateway IP is provided.

Is this some sort of permissions issues? Or perhaps something wrong with my Legato installation? I’ve tried resetting the userspace and reinstalling the platform to no avail. Any insight would be greatly appreciated.

When app use le_mdc_StartSession() to start data connection, it has to setup the route table as well, same is done by “cm data connect” itself, refer to below link for sample:

Reminded, the app needs to be unsandboxed before it can alter the route table.

Optionally, you may consider using le_data_Request() which should take care route table setting automatically.

Thx

Have you solved the problem now?
I have a similar problem now.[quote=“coffeebean, post:1, topic:2897, full:true”]
:pleading_face:

I don’t see problem WP77:

Have you tried if command line to use curl is working fine first?