mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/5] net: host command: move to commands/
Date: Mon, 10 Jun 2024 09:51:05 +0200	[thread overview]
Message-ID: <20240610075105.812496-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240610075105.812496-1-s.hauer@pengutronix.de>

Commands are usually implemented in the commands/ directory. Move the
host command there as well.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Makefile |  2 +-
 commands/host.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 net/dns.c         | 37 -------------------------------------
 3 files changed, 41 insertions(+), 38 deletions(-)
 create mode 100644 commands/host.c

diff --git a/commands/Makefile b/commands/Makefile
index 30e1f8403e..19a2dd3112 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -150,5 +150,5 @@ obj-$(CONFIG_CMD_TUTORIAL)	+= tutorial.o
 obj-$(CONFIG_CMD_STACKSMASH)	+= stacksmash.o
 obj-$(CONFIG_CMD_PARTED)	+= parted.o
 obj-$(CONFIG_CMD_EFI_HANDLE_DUMP)	+= efi_handle_dump.o
-
+obj-$(CONFIG_CMD_HOST)		+= host.o
 UBSAN_SANITIZE_ubsan.o := y
diff --git a/commands/host.c b/commands/host.c
new file mode 100644
index 0000000000..b931445056
--- /dev/null
+++ b/commands/host.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <command.h>
+#include <net.h>
+
+static int do_host(int argc, char *argv[])
+{
+	IPaddr_t ip;
+	int ret;
+	char *hostname, *varname = NULL;
+
+	if (argc < 2)
+		return COMMAND_ERROR_USAGE;
+
+	hostname = argv[1];
+
+	if (argc > 2)
+		varname = argv[2];
+
+	ret = resolv(argv[1], &ip);
+	if (ret) {
+		printf("unknown host %s\n", hostname);
+		return 1;
+	}
+
+	if (varname)
+		setenv_ip(varname, ip);
+	else
+		printf("%s is at %pI4\n", hostname, &ip);
+
+	return 0;
+}
+
+BAREBOX_CMD_START(host)
+	.cmd		= do_host,
+	BAREBOX_CMD_DESC("resolve a hostname")
+	BAREBOX_CMD_OPTS("<HOSTNAME> [VARIABLE]")
+	BAREBOX_CMD_GROUP(CMD_GRP_NET)
+BAREBOX_CMD_END
diff --git a/net/dns.c b/net/dns.c
index fdddb3f915..8fbd13cdc3 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -262,40 +262,3 @@ int resolv(const char *host, IPaddr_t *ip)
 
 	return 0;
 }
-
-#ifdef CONFIG_CMD_HOST
-static int do_host(int argc, char *argv[])
-{
-	IPaddr_t ip;
-	int ret;
-	char *hostname, *varname = NULL;
-
-	if (argc < 2)
-		return COMMAND_ERROR_USAGE;
-
-	hostname = argv[1];
-
-	if (argc > 2)
-		varname = argv[2];
-
-	ret = resolv(argv[1], &ip);
-	if (ret) {
-		printf("unknown host %s\n", hostname);
-		return 1;
-	}
-
-	if (varname)
-		setenv_ip(varname, ip);
-	else
-		printf("%s is at %pI4\n", hostname, &ip);
-
-	return 0;
-}
-
-BAREBOX_CMD_START(host)
-	.cmd		= do_host,
-	BAREBOX_CMD_DESC("resolve a hostname")
-	BAREBOX_CMD_OPTS("<HOSTNAME> [VARIABLE]")
-	BAREBOX_CMD_GROUP(CMD_GRP_NET)
-BAREBOX_CMD_END
-#endif
-- 
2.39.2




  parent reply	other threads:[~2024-06-10  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-10  7:51 [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer
2024-06-10  7:51 ` [PATCH 1/5] net: virtio-net: allow to set current MAC address Sascha Hauer
2024-06-10  7:51 ` [PATCH 2/5] net: ifup: use accessor to set network device ip/netmask Sascha Hauer
2024-06-10  7:51 ` [PATCH 3/5] net: add edev argument to net_set_gateway() Sascha Hauer
2024-06-10  7:51 ` [PATCH 4/5] net: establish single code path for setting edev parameters Sascha Hauer
2024-06-10  7:51 ` Sascha Hauer [this message]
2024-06-13  6:41 ` [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240610075105.812496-6-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox