diff options
author | Thomas Huth <thuth@redhat.com> | 2016-10-12 12:44:06 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-10-17 11:02:16 +1100 |
commit | f7eb3a5728042a659b66806f4654ef0da16d58b4 (patch) | |
tree | aabf4c927e54412afd033c93431bedd04de07589 /lib | |
parent | 725e9d28b783696261b9c35a9aeabad6990d8ef3 (diff) | |
download | SLOF-f7eb3a5728042a659b66806f4654ef0da16d58b4.zip SLOF-f7eb3a5728042a659b66806f4654ef0da16d58b4.tar.gz SLOF-f7eb3a5728042a659b66806f4654ef0da16d58b4.tar.bz2 |
libnet: Simplify the Forth-to-C wrapper of 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>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libnet/libnet.code | 15 | ||||
-rw-r--r-- | lib/libnet/netapps.h | 2 | ||||
-rw-r--r-- | lib/libnet/ping.c | 20 |
3 files changed, 15 insertions, 22 deletions
diff --git a/lib/libnet/libnet.code b/lib/libnet/libnet.code index a1c5a90..ab67fac 100644 --- a/lib/libnet/libnet.code +++ b/lib/libnet/libnet.code @@ -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 diff --git a/lib/libnet/netapps.h b/lib/libnet/netapps.h index 693de69..00b6318 100644 --- a/lib/libnet/netapps.h +++ b/lib/libnet/netapps.h @@ -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); diff --git a/lib/libnet/ping.c b/lib/libnet/ping.c index 3da519f..edad5eb 100644 --- a/lib/libnet/ping.c +++ b/lib/libnet/ping.c @@ -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; } |