@@ -19,18 +19,7 @@ PRIM(NET_X2d_LOAD)
MIRP
PRIM(NET_X2d_PING)
- int slen = TOS.n; POP;
+ int alen = 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);
+ TOS.n = ping(arg, alen);
MIRP
@@ -20,7 +20,7 @@ struct filename_ip;
extern int netboot(int argc, char *argv[]);
extern int netsave(int argc, char *argv[]);
-extern int ping(int argc, char *argv[]);
+extern int ping(char *args_fs, int alen);
extern int dhcp(char *ret_buffer, struct filename_ip *fn_ip,
unsigned int retries, int flags);
@@ -106,8 +106,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;
@@ -115,15 +114,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;
}
@@ -70,8 +70,5 @@ INSTANCE VARIABLE ciregs-buffer
;
: ping ( -- )
- s" ping " my-args $cat
- \ Zero-terminate string:
- s" " $cat 2dup + 1 - 0 swap c!
- net-ping
+ my-args net-ping
;
Now that we do not link libnet against net-snk anymore, we can change the prototype of ping() and thus simplify the "net-ping" Forth-to-C wrapper. There is no need to convert the parameters to a temporary argv[] array anymore. Signed-off-by: Thomas Huth <thuth@redhat.com> --- lib/libnet/libnet.code | 15 ++------------- lib/libnet/netapps.h | 2 +- lib/libnet/ping.c | 20 ++++++++++++-------- slof/fs/packages/obp-tftp.fs | 5 +---- 4 files changed, 16 insertions(+), 26 deletions(-)