[PATCH 4/9] net: dns: Allow to set variable with the resolved host

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

 



Add an additional [VARIABLE] parameter to the host command to allow
setting a variable with the resolved IP address.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 net/dns.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/net/dns.c b/net/dns.c
index d241781939..ffe98ef9e3 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -258,20 +258,26 @@ static int do_host(int argc, char *argv[])
 {
 	IPaddr_t ip;
 	int ret;
-	char *hostname;
+	char *hostname, *varname = NULL;
 
-	if (argc != 2)
+	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;
 	}
 
-	printf("%s is at %pI4\n", hostname, &ip);
+	if (varname)
+		setenv_ip(varname, ip);
+	else
+		printf("%s is at %pI4\n", hostname, &ip);
 
 	return 0;
 }
@@ -279,7 +285,7 @@ static int do_host(int argc, char *argv[])
 BAREBOX_CMD_START(host)
 	.cmd		= do_host,
 	BAREBOX_CMD_DESC("resolve a hostname")
-	BAREBOX_CMD_OPTS("HOSTNAME")
+	BAREBOX_CMD_OPTS("<HOSTNAME> [VARIABLE]")
 	BAREBOX_CMD_GROUP(CMD_GRP_NET)
 BAREBOX_CMD_END
 #endif
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



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

  Powered by Linux