summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-01-04 15:20:43 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-01-04 15:20:45 +0100
commit985bc4f2e150a999ce74f53bf8b8809b1aaed808 (patch)
tree5f8d3a9562ca3ff9689a0f60ccb6bdddfea0e152
parent80b2d315ce52f469a17622538b775b10e92fc9bc (diff)
downloadbarebox-985bc4f2e150a999ce74f53bf8b8809b1aaed808.tar.gz
net: dns: Allow to set variable with the resolved host
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@pengutronix.de>
-rw-r--r--net/dns.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/net/dns.c b/net/dns.c
index d241781..ffe98ef 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