[SLOF] [PATCH 09/11] Add a Forth-to-C wrapper for the ping command, too
Thomas Huth
thuth at redhat.com
Sat Sep 10 05:52:07 AEST 2016
Now that we link libnet to Paflof, we can call the ping
function there directly instead of using the one from
net-snk.
Signed-off-by: Thomas Huth <thuth at redhat.com>
---
lib/libnet/libnet.code | 7 +++++++
lib/libnet/libnet.in | 1 +
lib/libnet/netapps.h | 2 +-
lib/libnet/ping.c | 20 ++++++++++++--------
slof/fs/packages/obp-tftp.fs | 4 ++--
5 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/lib/libnet/libnet.code b/lib/libnet/libnet.code
index f528ba3..64325c7 100644
--- a/lib/libnet/libnet.code
+++ b/lib/libnet/libnet.code
@@ -1,5 +1,6 @@
extern int netboot(int argc, char *argv[]);
+extern int ping(char *args_fs, int alen);
PRIM(NET_X2d_LOAD)
int slen = TOS.n; POP;
@@ -17,3 +18,9 @@ PRIM(NET_X2d_LOAD)
}
TOS.n = netboot(i, argvs);
MIRP
+
+PRIM(NET_X2d_PING)
+ int alen = TOS.n; POP;
+ char *arg = TOS.a;
+ TOS.n = ping(arg, alen);
+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/lib/libnet/netapps.h b/lib/libnet/netapps.h
index d3f7eb2..6854a45 100644
--- a/lib/libnet/netapps.h
+++ b/lib/libnet/netapps.h
@@ -23,7 +23,7 @@ int netsave(int argc, char *argv[]);
int bcmflash(int argc, char *argv[]);
int mac_sync(int argc, char *argv[]);
int net_eeprom_version( void );
-int ping(int argc, char *argv[]);
+int ping(char *args_fs, int alen);
int dhcp(char *ret_buffer, filename_ip_t * fn_ip, unsigned int retries, int flags);
#endif
diff --git a/lib/libnet/ping.c b/lib/libnet/ping.c
index def3179..d35e221 100644
--- a/lib/libnet/ping.c
+++ b/lib/libnet/ping.c
@@ -105,8 +105,7 @@ parse_args(const char *args, struct ping_args *ping_args)
return 0;
}
-int
-ping(int argc, char *argv[])
+int ping(char *args_fs, int alen)
{
short arp_failed = 0;
filename_ip_t fn_ip;
@@ -114,15 +113,20 @@ ping(int argc, char *argv[])
struct ping_args ping_args;
uint8_t own_mac[6];
uint32_t netmask;
+ char args[256];
memset(&ping_args, 0, sizeof(struct ping_args));
- if (argc == 2) {
- if (parse_args(argv[1], &ping_args)) {
- usage();
- return -1;
- }
- } else {
+ if (alen <= 0 && alen >= sizeof(args) - 1) {
+ usage();
+ return -1;
+ }
+
+ /* Convert forth string into NUL-terminated C-string */
+ memcpy(args, args_fs, alen);
+ args[alen] = 0;
+
+ if (parse_args(args, &ping_args)) {
usage();
return -1;
}
diff --git a/slof/fs/packages/obp-tftp.fs b/slof/fs/packages/obp-tftp.fs
index e26025d..53d9531 100644
--- a/slof/fs/packages/obp-tftp.fs
+++ b/slof/fs/packages/obp-tftp.fs
@@ -69,6 +69,6 @@ INSTANCE VARIABLE ciregs-buffer
ciregs-buffer @ ciregs-size free-mem
;
-: ping ( -- )
- s" ping " my-args $cat (client-exec)
+: ping ( -- errno )
+ my-args net-ping
;
--
1.8.3.1
More information about the SLOF
mailing list