[PATCH v3 06/12] net-lwip: add dns command

Jerome Forissier jerome.forissier at linaro.org
Thu Jun 6 17:59:27 CEST 2024



On 6/6/24 17:46, Ilias Apalodimas wrote:
>> @@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o
>>  obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o
>>  obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o
>>  obj-$(CONFIG_CMD_DHCP) += dhcp.o
>> +obj-$(CONFIG_CMD_DNS) += dns.o
>>  obj-$(CONFIG_CMD_PING) += ping.o
>>  obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
>>
>> diff --git a/net-lwip/dns.c b/net-lwip/dns.c
>> new file mode 100644
>> index 00000000000..24a5149343a
>> --- /dev/null
>> +++ b/net-lwip/dns.c
>> @@ -0,0 +1,107 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/* Copyright (C) 2024 Linaro Ltd. */
>> +
>> +#include <command.h>
>> +#include <console.h>
>> +#include <lwip/dns.h>
>> +#include <lwip/timeouts.h>
>> +#include <net-lwip.h>
>> +#include <time.h>
>> +
>> +#define DNS_RESEND_MS 1000
>> +#define DNS_TIMEOUT_MS 10000
>> +
>> +static ulong start;
>> +static ip_addr_t host_ipaddr;
>> +static bool done;
>> +
>> +static void do_dns_tmr(void *arg)
>> +{
>> +       dns_tmr();
>> +}
>> +
>> +static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
>> +{
>> +       const char *var = arg;
>> +       char *ipstr = ip4addr_ntoa(ipaddr);
>> +
>> +       done = true;
>> +
>> +       if (!ipaddr) {
>> +               printf("DNS: host not found\n");
>> +               host_ipaddr.addr = 0;
>> +               return;
>> +       }
>> +
>> +       if (var)
>> +               env_set(var, ipstr);
> 
> Do we need this? Won't this set <dns_name> == ipaddr?

No, the syntax of the dns command is: 'dns hostname [env_var]' so one can
pretty much give any variable name to receive the IP address.

> If we do not need it repurpose the void *arg and get rid of the global 'done'

I could probably use a struct to get rid of the globals. Let me see what I can do.
 
>> +
>> +       printf("%s\n", ipstr);
>> +}
>> +
>> +int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>> +{
>> +       bool has_server = false;
>> +       ip_addr_t ipaddr;
>> +       ip_addr_t ns;
>> +       char *nsenv;
>> +       char *name;
>> +       char *var;
>> +       int ret;
> 
> [...]
> 
> Thanks
> /Ilias


More information about the U-Boot mailing list