[PATCHv8 15/15] net/lwip/wget add port selection

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Sep 13 08:30:36 CEST 2023


Hi Maxi,

I'd drop this from the series.  It's useful in the long run, but let's just
get the minimum functionality in first

Thanks
/Ilias
On Fri, Sep 08, 2023 at 07:53:20PM +0600, Maxim Uvarov wrote:
> Allow to specify HTTP port instead of just using default for wget command.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov at linaro.org>
> ---
>  include/net/lwip.h             |  2 +-
>  net/lwip/apps/http/lwip-wget.c | 40 +++++++++++++++++++++++++---------
>  2 files changed, 31 insertions(+), 11 deletions(-)
>
> diff --git a/include/net/lwip.h b/include/net/lwip.h
> index 1e92f9871c..6de646771e 100644
> --- a/include/net/lwip.h
> +++ b/include/net/lwip.h
> @@ -54,7 +54,7 @@ int ulwip_tftp(ulong addr, const char *filename);
>   *
>   *
>   * @addr:  start address to download result
> - * @url:   url in format http://host/url
> + * @url:   url in format http://host[:port]/url
>   * Returns: 0 for success, !0 if error
>   */
>  int ulwip_wget(ulong addr, char *url);
> diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c
> index 5c432056b1..7de1c962c6 100644
> --- a/net/lwip/apps/http/lwip-wget.c
> +++ b/net/lwip/apps/http/lwip-wget.c
> @@ -63,18 +63,38 @@ static int parse_url(char *url, char *host, u16 *port)
>  	p += strlen("http://");
>
>  	/* parse hostname */
> -	pp = strchr(p, '/');
> -	if (!pp) {
> -		return -2;
> +	pp = strchr(p, ':');
> +	if (pp) {
> +#define PORT_STR_SIZE 5
> +		char portstr[PORT_STR_SIZE];
> +
> +		if (pp - p >= SERVER_NAME_SIZE)
> +			return -2;
> +		memcpy(host, p, pp - p);
> +		host[pp - p + 1] = '\0';
> +
> +		p = pp + 1;
> +		pp = strchr(p, '/');
> +		if (!pp)
> +			return -3;
> +
> +		if (pp - p >= PORT_STR_SIZE)
> +			return -4;
> +		memcpy(portstr, p, pp - p);
> +		portstr[pp - p] = '\0';
> +		*port = (u16)dectoul(portstr, NULL);
> +	} else {
> +		pp = strchr(p, '/');
> +		if (!pp)
> +			return -5;
> +
> +		if (pp - p >= SERVER_NAME_SIZE)
> +			return -6;
> +		memcpy(host, p, pp - p);
> +		host[pp - p + 1] = '\0';
> +		*port = HTTP_PORT_DEFAULT;
>  	}
>
> -	if (pp - p >= SERVER_NAME_SIZE)
> -		return -3;
> -
> -	memcpy(host, p, pp - p);
> -	host[pp - p + 1] = '\0';
> -	*port = HTTP_PORT_DEFAULT;
> -
>  	return 0;
>  }
>
> --
> 2.30.2
>


More information about the U-Boot mailing list