[PATCH 5/5] net: host command: move to commands/

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux