system/ping[6]: correct the ping return value
MIRTOS-421 Change-Id: I68d8328ead736cd557d6142f611fae0540f74c1b Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
8b66a6238a
commit
c89e9330cc
@ -33,9 +33,10 @@
|
||||
|
||||
/* Positive number represent information */
|
||||
|
||||
#define ICMP_I_BEGIN 0 /* extra: not used */
|
||||
#define ICMP_I_ROUNDTRIP 1 /* extra: packet delay */
|
||||
#define ICMP_I_FINISH 2 /* extra: elapsed time */
|
||||
#define ICMP_I_OK 0 /* extra: not used */
|
||||
#define ICMP_I_BEGIN 1 /* extra: not used */
|
||||
#define ICMP_I_ROUNDTRIP 2 /* extra: packet delay */
|
||||
#define ICMP_I_FINISH 3 /* extra: elapsed time */
|
||||
|
||||
/* Negative odd number represent error(unrecoverable) */
|
||||
|
||||
|
@ -33,9 +33,10 @@
|
||||
|
||||
/* Positive number represent information */
|
||||
|
||||
#define ICMPv6_I_BEGIN 0 /* extra: not used */
|
||||
#define ICMPv6_I_ROUNDTRIP 1 /* extra: packet delay */
|
||||
#define ICMPv6_I_FINISH 2 /* extra: elapsed time */
|
||||
#define ICMPv6_I_OK 0 /* extra: not used */
|
||||
#define ICMPv6_I_BEGIN 1 /* extra: not used */
|
||||
#define ICMPv6_I_ROUNDTRIP 2 /* extra: packet delay */
|
||||
#define ICMPv6_I_FINISH 3 /* extra: elapsed time */
|
||||
|
||||
/* Negative odd number represent error(unrecoverable) */
|
||||
|
||||
|
@ -41,6 +41,15 @@
|
||||
#define ICMP_NPINGS 10 /* Default number of pings */
|
||||
#define ICMP_POLL_DELAY 1000 /* 1 second in milliseconds */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct ping_priv_s
|
||||
{
|
||||
int code; /* Notice code ICMP_I/E/W_XXX */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -90,6 +99,13 @@ static void show_usage(FAR const char *progname, int exitcode)
|
||||
|
||||
static void ping_result(FAR const struct ping_result_s *result)
|
||||
{
|
||||
FAR struct ping_priv_s *priv = result->info->priv;
|
||||
|
||||
if (result->code < 0)
|
||||
{
|
||||
priv->code = result->code;
|
||||
}
|
||||
|
||||
switch (result->code)
|
||||
{
|
||||
case ICMP_E_HOSTIP:
|
||||
@ -215,6 +231,7 @@ static void ping_result(FAR const struct ping_result_s *result)
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
struct ping_info_s info;
|
||||
struct ping_priv_s priv;
|
||||
FAR char *endptr;
|
||||
int exitcode;
|
||||
int option;
|
||||
@ -224,6 +241,8 @@ int main(int argc, FAR char *argv[])
|
||||
info.delay = ICMP_POLL_DELAY;
|
||||
info.timeout = ICMP_POLL_DELAY;
|
||||
info.callback = ping_result;
|
||||
info.priv = &priv;
|
||||
priv.code = ICMP_I_OK;
|
||||
|
||||
/* Parse command line options */
|
||||
|
||||
@ -314,7 +333,7 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
info.hostname = argv[optind];
|
||||
icmp_ping(&info);
|
||||
return EXIT_SUCCESS;
|
||||
return priv.code < 0 ? EXIT_FAILURE: EXIT_SUCCESS;
|
||||
|
||||
errout_with_usage:
|
||||
optind = 0;
|
||||
|
@ -43,6 +43,15 @@
|
||||
#define ICMPv6_NPINGS 10 /* Default number of pings */
|
||||
#define ICMPv6_POLL_DELAY 1000 /* 1 second in milliseconds */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct ping6_priv_s
|
||||
{
|
||||
int code; /* Notice code ICMP_I/E/W_XXX */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -92,8 +101,14 @@ static void show_usage(FAR const char *progname, int exitcode)
|
||||
|
||||
static void ping6_result(FAR const struct ping6_result_s *result)
|
||||
{
|
||||
FAR struct ping6_priv_s *priv = result->info->priv;
|
||||
char strbuffer[INET6_ADDRSTRLEN];
|
||||
|
||||
if (result->code < 0)
|
||||
{
|
||||
priv->code = result->code;
|
||||
}
|
||||
|
||||
switch (result->code)
|
||||
{
|
||||
case ICMPv6_E_HOSTIP:
|
||||
@ -213,6 +228,7 @@ static void ping6_result(FAR const struct ping6_result_s *result)
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
struct ping6_info_s info;
|
||||
struct ping6_priv_s priv;
|
||||
FAR char *endptr;
|
||||
int exitcode;
|
||||
int option;
|
||||
@ -222,6 +238,8 @@ int main(int argc, FAR char *argv[])
|
||||
info.delay = ICMPv6_POLL_DELAY;
|
||||
info.timeout = ICMPv6_POLL_DELAY;
|
||||
info.callback = ping6_result;
|
||||
info.priv = &priv;
|
||||
priv.code = ICMPv6_I_OK;
|
||||
|
||||
/* Parse command line options */
|
||||
|
||||
@ -312,7 +330,7 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
info.hostname = argv[optind];
|
||||
icmp6_ping(&info);
|
||||
return EXIT_SUCCESS;
|
||||
return priv.code < 0 ? EXIT_FAILURE: EXIT_SUCCESS;
|
||||
|
||||
errout_with_usage:
|
||||
optind = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user