diff --git a/common/blspec.c b/common/blspec.c index 2c682e1..41f2a4c 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -303,9 +303,11 @@ goto out; } - ip = resolv(host); - if (ip == 0) + ret = resolv(host, &ip); + if (ret) { + pr_err("Cannot resolve \"%s\": %s\n", host, strerror(-ret)); goto out; + } hostpath = basprintf("%pI4:%s", &ip, path); diff --git a/fs/nfs.c b/fs/nfs.c index eb5db34..d7f1566 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -1293,7 +1293,11 @@ npriv->path = xstrdup(path + 1); - npriv->server = resolv(tmp); + ret = resolv(tmp, &npriv->server); + if (ret) { + printf("cannot resolve \"%s\": %s\n", tmp, strerror(-ret)); + goto err1; + } debug("nfs: server: %s path: %s\n", tmp, npriv->path); diff --git a/fs/tftp.c b/fs/tftp.c index 0d9ee6e..907adc7 100644 --- a/fs/tftp.c +++ b/fs/tftp.c @@ -696,10 +696,15 @@ struct tftp_priv *priv = xzalloc(sizeof(struct tftp_priv)); struct super_block *sb = &fsdev->sb; struct inode *inode; + int ret; dev->priv = priv; - priv->server = resolv(fsdev->backingstore); + ret = resolv(fsdev->backingstore, &priv->server); + if (ret) { + pr_err("Cannot resolve \"%s\": %s\n", fsdev->backingstore, strerror(-ret)); + goto err; + } sb->s_op = &tftp_ops; @@ -707,6 +712,10 @@ sb->s_root = d_make_root(inode); return 0; +err: + free(priv); + + return ret; } static void tftp_remove(struct device_d *dev) diff --git a/include/net.h b/include/net.h index a09cb15..6912a55 100644 --- a/include/net.h +++ b/include/net.h @@ -330,13 +330,11 @@ void ethaddr_to_string(const u8 enetaddr[6], char *str); #ifdef CONFIG_NET_RESOLV -IPaddr_t resolv(const char *host); +int resolv(const char *host, IPaddr_t *ip); #else -static inline IPaddr_t resolv(const char *host) +static inline int resolv(const char *host, IPaddr_t *ip) { - IPaddr_t ip = 0; - string_to_ip(host, &ip); - return ip; + return string_to_ip(host, ip); } #endif diff --git a/net/dhcp.c b/net/dhcp.c index 79aa75d..670a6a6 100644 --- a/net/dhcp.c +++ b/net/dhcp.c @@ -562,6 +562,8 @@ int dhcp_set_result(struct eth_device *edev, struct dhcp_result *res) { + int ret; + net_set_ip(edev, res->ip); net_set_netmask(edev, res->netmask); net_set_gateway(res->gateway); @@ -580,8 +582,8 @@ if (res->tftp_server_name) { IPaddr_t ip; - ip = resolv(res->tftp_server_name); - if (ip) + ret = resolv(res->tftp_server_name, &ip); + if (!ret) net_set_serverip_empty(ip); } else if (res->serverip) { net_set_serverip_empty(res->serverip); diff --git a/net/dns.c b/net/dns.c index a3a3b94..4516235 100644 --- a/net/dns.c +++ b/net/dns.c @@ -201,26 +201,27 @@ net_eth_to_udplen(packet)); } -IPaddr_t resolv(const char *host) +int resolv(const char *host, IPaddr_t *ip) { - IPaddr_t ip; + IPaddr_t nameserver; - if (!string_to_ip(host, &ip)) - return ip; + if (!string_to_ip(host, ip)) + return 0; dns_ip = 0; + *ip = 0; dns_state = STATE_INIT; - ip = net_get_nameserver(); - if (!ip) { + nameserver = net_get_nameserver(); + if (!nameserver) { pr_err("no nameserver specified in $net.nameserver\n"); return 0; } - pr_debug("resolving host %s via nameserver %pI4\n", host, &ip); + pr_debug("resolving host %s via nameserver %pI4\n", host, &nameserver); - dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL); + dns_con = net_udp_new(nameserver, DNS_PORT, dns_handler, NULL); if (IS_ERR(dns_con)) return PTR_ERR(dns_con); dns_timer_start = get_time_ns(); @@ -240,25 +241,32 @@ net_unregister(dns_con); - pr_debug("host %s is at %pI4\n", host, &dns_ip); + if (dns_ip) { + pr_debug("host %s is at %pI4\n", host, &dns_ip); + } else { + pr_debug("host %s not found\n", host); + return -ENOENT; + } - return dns_ip; + *ip = dns_ip; + + return 0; } #ifdef CONFIG_CMD_HOST static int do_host(int argc, char *argv[]) { IPaddr_t ip; + int ret; if (argc != 2) return COMMAND_ERROR_USAGE; - ip = resolv(argv[1]); - if (!ip) + ret = resolv(argv[1], &ip); + if (ret) printf("unknown host %s\n", argv[1]); - else { + else printf("%s is at %pI4\n", argv[1], &ip); - } return 0; } diff --git a/net/net.c b/net/net.c index 63f42fa..f1a7df0 100644 --- a/net/net.c +++ b/net/net.c @@ -107,7 +107,9 @@ if (!string_to_ip(var, &ip)) return ip; - return resolv((char*)var); + resolv(var, &ip); + + return ip; } int setenv_ip(const char *name, IPaddr_t ip) diff --git a/net/ping.c b/net/ping.c index b592628..a71f59a 100644 --- a/net/ping.c +++ b/net/ping.c @@ -61,9 +61,9 @@ if (argc < 2) return COMMAND_ERROR_USAGE; - net_ping_ip = resolv(argv[1]); - if (!net_ping_ip) { - printf("unknown host %s\n", argv[1]); + ret = resolv(argv[1], &net_ping_ip); + if (ret) { + printf("Cannot resolve \"%s\": %s\n", argv[1], strerror(-ret)); return 1; } diff --git a/net/sntp.c b/net/sntp.c index 577c859..b4e6d64 100644 --- a/net/sntp.c +++ b/net/sntp.c @@ -120,9 +120,9 @@ if (!server) return -EINVAL; - net_sntp_ip = resolv(server); - if (!net_sntp_ip) { - printf("unknown host %s\n", server); + ret = resolv(server, &net_sntp_ip); + if (ret) { + printf("Cannot resolve \"%s\": %s\n", server, strerror(-ret));; return 1; }