From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC v2 14/16] net: picotcp: add ping command
Date: Sun, 19 Jul 2015 23:07:21 +0300 [thread overview]
Message-ID: <1437336443-8076-15-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1437336443-8076-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
net/Makefile | 1 +
net/picotcp/Kconfig | 5 ++++
net/picotcp_ping.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+)
diff --git a/net/Makefile b/net/Makefile
index d5b133b..04e347f 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_NET_PICOTCP) += picotcp.o
obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o
obj-$(CONFIG_CMD_PICOTCP_IFCONFIG) += picotcp_ifconfig.o
+obj-$(CONFIG_CMD_PICOTCP_PING) += picotcp_ping.o
diff --git a/net/picotcp/Kconfig b/net/picotcp/Kconfig
index 9a2d628..cb60001 100644
--- a/net/picotcp/Kconfig
+++ b/net/picotcp/Kconfig
@@ -43,4 +43,9 @@ config CMD_PICOTCP_IFCONFIG
depends on NET_PICO_SUPPORT_IPV4
prompt "ifconfig command"
+config CMD_PICOTCP_PING
+ bool
+ depends on NET_PICO_SUPPORT_ICMP4
+ prompt "ping command"
+
endif # NET_PICOTCP
diff --git a/net/picotcp_ping.c b/net/picotcp_ping.c
new file mode 100644
index 0000000..ed69fb5
--- /dev/null
+++ b/net/picotcp_ping.c
@@ -0,0 +1,85 @@
+#include <command.h>
+#include <common.h>
+#include <complete.h>
+#include <driver.h>
+#include <poller.h>
+
+#include <pico_stack.h>
+#include <pico_ipv4.h>
+#include <pico_dev_null.h>
+#include <pico_dhcp_client.h>
+#include <pico_icmp4.h>
+
+#define NUM_PING 3
+
+static int ping_done;
+static int ping_code;
+
+/* callback function for receiving ping reply */
+void cb_ping(struct pico_icmp4_stats *s)
+{
+ char host[30];
+ int time_sec = 0;
+ int time_msec = 0;
+
+ /* convert ip address from icmp4_stats structure to string */
+ pico_ipv4_to_string(host, s->dst.addr);
+
+ /* get time information from icmp4_stats structure */
+ time_sec = s->time / 1000;
+ time_msec = s->time % 1000;
+
+ if (s->err == PICO_PING_ERR_REPLIED) {
+ /* print info if no error reported in icmp4_stats structure */
+ printf("%lu bytes from %s: icmp_req=%lu ttl=%lu time=%llu ms\n", \
+ s->size, host, s->seq, s->ttl, s->time);
+ if (s->seq == NUM_PING) {
+ ping_done = 1;
+ }
+ } else {
+ /* else, print error info */
+ printf("PING %lu to %s: Error %d\n", s->seq, host, s->err);
+ ping_done = 1;
+ }
+
+ ping_code = s->err;
+}
+
+static int do_picoping(int argc, char *argv[])
+{
+ int id;
+
+ if (argc < 1) {
+ perror("picoping");
+ return 1;
+ }
+
+ id = pico_icmp4_ping(argv[1], NUM_PING, 1000, 5000, 48, cb_ping);
+
+ if (id == -1) {
+ return -EIO;
+ }
+
+ ping_done = 0;
+ ping_code = PICO_PING_ERR_PENDING;
+
+ while (!ping_done) {
+ if (ctrlc()) {
+ break;
+ }
+ get_time_ns();
+ poller_call();
+ }
+
+ pico_icmp4_ping_abort(id);
+
+ if (ping_code != PICO_PING_ERR_REPLIED) {
+ return -EIO;
+ }
+
+ return 0;
+}
+
+BAREBOX_CMD_START(picoping)
+ .cmd = do_picoping,
+BAREBOX_CMD_END
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-07-19 20:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-19 20:07 [RFC v2 00/16] barebox picotcp integration (2015.07.19) Antony Pavlov
2015-07-19 20:07 ` [RFC v2 01/16] net_udp_bind(): use uint16_t type for source port Antony Pavlov
2015-07-19 20:07 ` [RFC v2 02/16] fs/tftp.c: drop unused server_port variable Antony Pavlov
2015-07-19 20:07 ` [RFC v2 03/16] fs/nfs.c: use uint16_t for port numbers Antony Pavlov
2015-07-19 20:07 ` [RFC v2 04/16] fs/nfs.c: use SUNRPC_PORT remote port by default Antony Pavlov
2015-07-19 20:07 ` [RFC v2 05/16] net: change UDP handler function API Antony Pavlov
2015-07-19 20:07 ` [RFC v2 06/16] net: change net_udp_send() API Antony Pavlov
2015-07-19 20:07 ` [RFC v2 07/16] net: introduce setudppeerport() Antony Pavlov
2015-07-19 20:07 ` [RFC v2 08/16] net: import picotcp from github Antony Pavlov
2015-07-19 20:07 ` [RFC v2 09/16] picotcp: add barebox target support Antony Pavlov
2015-07-19 20:07 ` [RFC v2 10/16] picotcp: switch to Kbuild Antony Pavlov
2015-07-19 20:07 ` [RFC v2 11/16] net: add initial picotcp support Antony Pavlov
2015-07-19 20:07 ` [RFC v2 12/16] net: picotcp: add test_picotcp command Antony Pavlov
2015-07-19 20:07 ` [RFC v2 13/16] net: picotcp: add ifconfig command Antony Pavlov
2015-07-19 20:07 ` Antony Pavlov [this message]
2015-07-19 20:07 ` [RFC v2 15/16] net: picotcp: add route command Antony Pavlov
2015-07-19 20:07 ` [RFC v2 16/16] sandbox_defconfig: switch to picotcp Antony Pavlov
2015-07-20 7:10 ` [RFC v2 00/16] barebox picotcp integration (2015.07.19) Sascha Hauer
2015-07-20 9:50 ` Antony Pavlov
2015-07-20 10:06 ` Antony Pavlov
2015-07-20 10:45 ` Sascha Hauer
2015-07-20 12:16 ` Antony Pavlov
2015-07-24 4:58 ` Antony Pavlov
2015-07-24 7:19 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437336443-8076-15-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox