From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Maxim Uvarov <maxim.uvarov@linaro.org>
Cc: u-boot@lists.denx.de, pbrobinson@redhat.com,
joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com,
goldsimon@gmx.de, lwip-devel@nongnu.org
Subject: Re: [PATCHv4 5/5] net/lwip: apps/http: add dns support
Date: Thu, 27 Jul 2023 15:59:15 +0300 [thread overview]
Message-ID: <ZMJqIxmXJD4S72Ig@hades> (raw)
In-Reply-To: <20230714142000.5534-6-maxim.uvarov@linaro.org>
On Fri, Jul 14, 2023 at 08:20:00PM +0600, Maxim Uvarov wrote:
> provide hostname to client and allow lwip to resolve it.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
> lib/lwip/apps/http/lwip-wget.c | 59 ++++++++++++++++++++++++++++++----
> 1 file changed, 53 insertions(+), 6 deletions(-)
>
> diff --git a/lib/lwip/apps/http/lwip-wget.c b/lib/lwip/apps/http/lwip-wget.c
> index 0308b0b04a..db553a0f14 100644
> --- a/lib/lwip/apps/http/lwip-wget.c
> +++ b/lib/lwip/apps/http/lwip-wget.c
> @@ -45,18 +45,65 @@ static void httpc_result(void *arg, httpc_result_t httpc_result, u32_t rx_conten
> }
> }
>
> +/* http://hostname:port/url */
> +static int parse_url(char *url, char *host, int *port)
> +{
> + int ret;
> + char *p, *pp;
> +
> + p = strstr(url, "http://");
> + if (!p) {
> + printf("err: no http://!\n");
> + return -1;
> + }
> +
> + p += strlen("http://");
> +
> + /* parse hostname */
> + pp = strchr(p, ':');
> + if (pp) {
> + char portstr[5];
> +
> + memcpy(host, p, pp - p);
You are copying bytes over without taking into account the length of the
array. Also, I think we should keep things as simple as possible for the
first iteration, so can we ignore the port config for now and just stick to
80?
Thanks
/Ilias
> + host[pp - p + 1] = '\0';
> +
> + p = pp + 1;
> + pp = strchr(p, '/');
> + if (!pp) {
> + printf("wrong url\n");
> + return -2;
> + }
> +
> + memcpy(portstr, p, pp - p);
> + portstr[pp - p] = '\0';
> + *port = atoi(portstr);
> + } else {
> + pp = strchr(p, '/');
> + if (!pp) {
> + printf("wrong url\n");
> + return -3;
> + }
> + memcpy(host, p, pp - p);
> + host[pp - p + 1] = '\0';
> + *port = 80; /* default */
> + }
> +
> + return 0;
> +}
> +
> int lwip_wget(ulong addr, char *url)
> {
> err_t err;
> - int port = 80;
> - char *server_name;
> + int port;
> + char server_name[80];
> httpc_state_t *connection;
>
> daddr = addr;
> - server_name = env_get("serverip");
> - if (!server_name) {
> - printf("error: serverip variable has to be set\n");
> - return CMD_RET_FAILURE;
> +
> + err = parse_url(url, server_name, &port);
> + if (err) {
> + printf("error parse_url\n");
> + return -1;
> }
>
> printf("downloading %s to addr 0x%lx\n", url, addr);
> --
> 2.30.2
>
next prev parent reply other threads:[~2023-07-27 12:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 14:19 [PATCHv4 0/5] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-07-14 14:19 ` [PATCHv4 1/5] net/lwip: add lwip-external submodule Maxim Uvarov
2023-07-27 12:34 ` Ilias Apalodimas
2023-07-28 18:08 ` Tom Rini
2023-07-28 22:17 ` Simon Glass
2023-07-30 22:06 ` Peter Robinson
2023-08-02 8:03 ` Maxim Uvarov
2023-08-02 16:32 ` Tom Rini
2023-07-14 14:19 ` [PATCHv4 2/5] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-07-27 13:29 ` Ilias Apalodimas
2023-07-27 14:23 ` Maxim Uvarov
2023-07-28 14:26 ` Maxim Uvarov
2023-07-14 14:19 ` [PATCHv4 3/5] net/lwip: add doc/develop/net_lwip.rst Maxim Uvarov
2023-07-27 12:33 ` Ilias Apalodimas
2023-07-14 14:19 ` [PATCHv4 4/5] net/lwip: add dns command Maxim Uvarov
2023-07-14 14:20 ` [PATCHv4 5/5] net/lwip: apps/http: add dns support Maxim Uvarov
2023-07-27 12:59 ` Ilias Apalodimas [this message]
2023-07-27 12:22 ` [PATCHv4 0/5] net/lwip: add lwip library for the network stack Ilias Apalodimas
2023-07-28 1:51 ` Simon Glass
2023-07-28 11:24 ` Maxim Uvarov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZMJqIxmXJD4S72Ig@hades \
--to=ilias.apalodimas@linaro.org \
--cc=goldsimon@gmx.de \
--cc=joe.hershberger@ni.com \
--cc=lwip-devel@nongnu.org \
--cc=maxim.uvarov@linaro.org \
--cc=pbrobinson@redhat.com \
--cc=rfried.dev@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox