From patchwork Wed Oct 12 10:44:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 681117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sv9Tl4kntz9sfH for ; Wed, 12 Oct 2016 21:44:27 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sv9Tl40BczDsrm for ; Wed, 12 Oct 2016 21:44:27 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sv9TZ0ln4zDswv for ; Wed, 12 Oct 2016 21:44:18 +1100 (AEDT) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8097E90E5C; Wed, 12 Oct 2016 10:44:16 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-104.ams2.redhat.com [10.36.116.104]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9CAi8PY018047; Wed, 12 Oct 2016 06:44:15 -0400 From: Thomas Huth To: slof@lists.ozlabs.org Date: Wed, 12 Oct 2016 12:44:06 +0200 Message-Id: <1476269048-13895-5-git-send-email-thuth@redhat.com> In-Reply-To: <1476269048-13895-1-git-send-email-thuth@redhat.com> References: <1476269048-13895-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 12 Oct 2016 10:44:16 +0000 (UTC) Subject: [SLOF] [PATCH v3 4/6] libnet: Simplify the Forth-to-C wrapper of ping() X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" 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 --- 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(-) 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; } diff --git a/slof/fs/packages/obp-tftp.fs b/slof/fs/packages/obp-tftp.fs index 84ac439..30070a6 100644 --- a/slof/fs/packages/obp-tftp.fs +++ b/slof/fs/packages/obp-tftp.fs @@ -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 ;