[SLOF] [PATCH v3 2/6] Add a Forth-to-C wrapper for the ping command, too

Thomas Huth thuth at redhat.com
Wed Oct 12 21:44:04 AEDT 2016


Now that we link libnet to Paflof, we can call the ping
function there directly instead of using the one from
net-snk. We add a similar Forth-to-C wrapper like it has
already been done for netboot() - simplification and clean-up
will be done in a later patch once we do not link against
net-snk anymore.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 clients/net-snk/app/main.c   |  2 --
 lib/libnet/libnet.code       | 17 +++++++++++++++++
 lib/libnet/libnet.in         |  1 +
 slof/fs/packages/obp-tftp.fs |  5 ++++-
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/clients/net-snk/app/main.c b/clients/net-snk/app/main.c
index 3a01ac6..0dde404 100644
--- a/clients/net-snk/app/main.c
+++ b/clients/net-snk/app/main.c
@@ -31,8 +31,6 @@ main(int argc, char *argv[])
 	int i;
 	of_set_callback((void *) &_callback_entry);
 
-	if (strcmp(argv[0], "ping") == 0)
-		return ping(argc, argv);
 #ifdef SNK_BIOSEMU_APPS
 	// BIOS Emulator applications
 	if (strcmp(argv[0], "biosemu") == 0)
diff --git a/lib/libnet/libnet.code b/lib/libnet/libnet.code
index 66f955f..a1c5a90 100644
--- a/lib/libnet/libnet.code
+++ b/lib/libnet/libnet.code
@@ -17,3 +17,20 @@ PRIM(NET_X2d_LOAD)
 	}
 	TOS.n = netboot(i, argvs);
 MIRP
+
+PRIM(NET_X2d_PING)
+	int slen = TOS.n; POP;
+	char *arg = TOS.a;
+	char *argvs[8];
+	int i, p;
+	argvs[0] = arg;
+	i = 1;
+	for (p = 0; p < slen; p++) {
+		if (arg[p] == ' ') {
+			arg[p] = 0;
+			argvs[i] = &arg[p + 1];
+			i++;
+		}
+	}
+	TOS.n = ping(i, argvs);
+MIRP
diff --git a/lib/libnet/libnet.in b/lib/libnet/libnet.in
index 365587c..00b8658 100644
--- a/lib/libnet/libnet.in
+++ b/lib/libnet/libnet.in
@@ -1,2 +1,3 @@
 
 cod(NET-LOAD)
+cod(NET-PING)
diff --git a/slof/fs/packages/obp-tftp.fs b/slof/fs/packages/obp-tftp.fs
index e26025d..84ac439 100644
--- a/slof/fs/packages/obp-tftp.fs
+++ b/slof/fs/packages/obp-tftp.fs
@@ -70,5 +70,8 @@ INSTANCE VARIABLE ciregs-buffer
 ;
 
 : ping  ( -- )
-   s" ping " my-args $cat (client-exec)
+    s" ping " my-args $cat
+    \ Zero-terminate string:
+    s"  " $cat 2dup + 1 - 0 swap c!
+    net-ping
 ;
-- 
1.8.3.1



More information about the SLOF mailing list