diff options
| author | Jerome Forissier <[email protected]> | 2025-06-25 15:19:16 +0200 |
|---|---|---|
| committer | Jerome Forissier <[email protected]> | 2025-07-08 11:07:37 +0200 |
| commit | 9501274f94f02ee55059814033ea727180e310cb (patch) | |
| tree | e5bc70bd18077accd12ce2d9bc6380049436105f /net | |
| parent | 1361d9f4f00ad0a6e481cc947b75e8788982878f (diff) | |
lwip: add net_lwip_dns_resolve()
Add a helper fonction to convert an IP address (supplied as a text
string) or a host name to an ip_addr_t.
Signed-off-by: Jerome Forissier <[email protected]>
Diffstat (limited to 'net')
| -rw-r--r-- | net/lwip/net-lwip.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c index 040b51e8852..3918d57d7e5 100644 --- a/net/lwip/net-lwip.c +++ b/net/lwip/net-lwip.c @@ -7,6 +7,7 @@ #include <dm/device.h> #include <dm/uclass.h> #include <hexdump.h> +#include <linux/kernel.h> #include <lwip/ip4_addr.h> #include <lwip/dns.h> #include <lwip/err.h> @@ -358,6 +359,44 @@ int net_lwip_rx(struct udevice *udev, struct netif *netif) return len; } +/** + * net_lwip_dns_resolve() - find IP address from name or IP + * + * @name_or_ip: host name or IP address + * @ip: output IP address + * + * Return value: 0 on success, -1 on failure. + */ +int net_lwip_dns_resolve(char *name_or_ip, ip_addr_t *ip) +{ +#if defined(CONFIG_CMD_DNS) + char *var = "_dnsres"; + char *argv[] = { "dns", name_or_ip, var, NULL }; + int argc = ARRAY_SIZE(argv) - 1; +#endif + + if (ipaddr_aton(name_or_ip, ip)) + return 0; + +#if defined(CONFIG_CMD_DNS) + if (do_dns(NULL, 0, argc, argv) != CMD_RET_SUCCESS) + return -1; + + name_or_ip = env_get(var); + if (!name_or_ip) + return -1; + + if (!ipaddr_aton(name_or_ip, ip)) + return -1; + + env_set(var, NULL); + + return 0; +#else + return -1; +#endif +} + void net_process_received_packet(uchar *in_packet, int len) { #if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) |
