Use ping from within Application code

I want to have my App try periodically ping certain address (8.8.8.8 for example)to make sure my connection is fine. When I looked though documentation for legato all I can find is using ping via System() call. when I tried doing that as the example shows I always have a fail somewhere and if it does get to system call it always fails at the following ASSERT:

// Ping to test the connectivity
status = system(systemCmd);
if (WEXITSTATUS(status))
{
    le_mdc_StopSession(profileRef);
}
LE_ASSERT(!WEXITSTATUS(status));

And the process is killed & restarted & then we go through the same process.

  1. Is there a reason for this to be failing? I’m using the exact code from this example:
    Sample code for Data Statistics - Legato Docs
    except I added the following line at beginning:
        le_mdc_ProfileRef_t profileRef = le_mdc_GetProfile(LE_MDC_DEFAULT_PROFILE);
  1. Is there an inside function i can use to test ping functionality instead of going though a System call?

Have you tried to write socket program to send and reveive the ICMP packet?
This should be the same as ping command.
And you can search some ICMP sample code in Google easily.

2 Likes

Use a raw socket that will allow you to implement source selection a useful method is to use hop count to allow traceroute type functionality this was not hard to implement

This looks like a WAN health check feature. You can do PING, DNS lookup or even HTTP request.

Hi @mg_bg,
Can you try with sandboxed:true in .adef file of your application?
Because for me when i tried to use system command with sandboxed:false it was failing, But with sandboxed:true system command was working fine.

Please give a try.

Regards,
Muralidhara N.

@muralinagraj I tried using it with sandboxed:true in adef but no luck. I mean it doesn’t fail but it doesn’t seem to do anything at all. I’m trying to run the following to rebbot the whole system:

        char systemCmd[200] = {0};
	int status;

	snprintf(systemCmd, sizeof(systemCmd), "reboot");
	status = system(systemCmd);

but the system never reboots at all.

Also according to the legato documentation, the sandboxed option is set to true by default so you do only need to set it when you want it to be false.

To reboot system, please refer to the topic below:

Reset modem API function - #5 by jyijyi

@jyijyi I did end up using your approach from : Reset modem API function - #5 by jyijyi. I was just testing out @muralinagraj suggestion for sandboxed option.

Has this issue been resolved?

Hi mg_bg,
I also encountered such a problem, how do you solve it