You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/06/22 13:28:30 UTC
[incubator-nuttx-apps] branch master updated: system/ping[6]:
correct the ping return value
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new c89e933 system/ping[6]: correct the ping return value
c89e933 is described below
commit c89e9330ccf0c70ef1a263d41b4c259cc79cf174
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Feb 22 12:43:10 2021 +0800
system/ping[6]: correct the ping return value
MIRTOS-421
Change-Id: I68d8328ead736cd557d6142f611fae0540f74c1b
Signed-off-by: chao.an <an...@xiaomi.com>
---
include/netutils/icmp_ping.h | 7 ++++---
include/netutils/icmpv6_ping.h | 7 ++++---
system/ping/ping.c | 21 ++++++++++++++++++++-
system/ping6/ping6.c | 20 +++++++++++++++++++-
4 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/include/netutils/icmp_ping.h b/include/netutils/icmp_ping.h
index a4e510b..93652c8 100644
--- a/include/netutils/icmp_ping.h
+++ b/include/netutils/icmp_ping.h
@@ -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) */
diff --git a/include/netutils/icmpv6_ping.h b/include/netutils/icmpv6_ping.h
index 498b194..e3014d8 100644
--- a/include/netutils/icmpv6_ping.h
+++ b/include/netutils/icmpv6_ping.h
@@ -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) */
diff --git a/system/ping/ping.c b/system/ping/ping.c
index 20d08c0..e259fd9 100644
--- a/system/ping/ping.c
+++ b/system/ping/ping.c
@@ -42,6 +42,15 @@
#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;
diff --git a/system/ping6/ping6.c b/system/ping6/ping6.c
index 4ef3772..5fb6c1a 100644
--- a/system/ping6/ping6.c
+++ b/system/ping6/ping6.c
@@ -44,6 +44,15 @@
#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;