From patchwork Fri Sep 8 13:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720828 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779762wrp; Fri, 8 Sep 2023 06:58:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBvstpx5E0UrTNoc0yGQrDPvBfDCQdQYyKqV5IFTaUK00+SaSCuJu4K2JbCc/3eyiTe3+/ X-Received: by 2002:a1c:790b:0:b0:401:c8b9:4b86 with SMTP id l11-20020a1c790b000000b00401c8b94b86mr1657404wme.9.1694181492169; Fri, 08 Sep 2023 06:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181492; cv=none; d=google.com; s=arc-20160816; b=KJh56qpW8xyu6pjezWjuhDEv0q/hh9ZOLdjf4JFagkwbXof1dyWuYw8GemQEHemdOt /jD+lAQ2F9yReQqCoQczp+gVsXsJqfvSEUP3OIAGS2mvEfG1vUJ2YEf+6I3MVo+FOwNz X7okyxhYWPElTU3LtbLT8UK8+lGhQKd5ye/fV+6nNguhT7P8dx038sqqt9U8b3W02vq9 vmXJ4+Scpo7B9sH7DAlk5OV1Ob44zTuGX7ldOF+yp4lc4r8o0l2d2wgJMYZSO7Kxiigy 0Hkjf+DvLqLfoKbSU4ZgBu8qyKgHUCU6aYS7zCFwUQ+t1luiuUmNe8zT1EnRHFTAY0PG 6xmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=T4bNs11jp2uvKRM6X+fHHrjQC5wTl7DABBUZd6UAvRBdFsTlVHhi7xUndUcKAxUSm9 ao1Z8IeDG4xXEyd6Xigez7675/8k9Oc2/fMYcrJ+iXCPK51lVC6VobJQxskWfvlVIhas NCQvp28CyW0+8DsQeQRaapcpJTlBpfJdtIroYKmUQD0rTyLH7GhZcI37XnAnrjN5eZHU ZrijT17Kq2rFiJhYLdLcCLBgHsPnIYlQnNKAuXIVJUbYMcfcX56UWXZGy7973ZWm2mKL vep4kcH2u+ttmjVqeJgG6suElYd+DsKRJhA5gO/NS4yNKPAUTHSoaSFQX9u6M6vUgKPv R+Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q416S07D; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id bh5-20020a05600c3d0500b00400f8f92c08si887041wmb.52.2023.09.08.06.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q416S07D; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C807886AC6; Fri, 8 Sep 2023 15:56:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Q416S07D"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CA3486ABC; Fri, 8 Sep 2023 15:56:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E601286ACC for ; Fri, 8 Sep 2023 15:56:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2bcc331f942so25289921fa.0 for ; Fri, 08 Sep 2023 06:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181370; x=1694786170; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; b=Q416S07Duidun2Jo2psxBsuHWBrpWy3AYMWuzWYJ7G2wvnNyJ1nyO8dMRoJhc7G7yv Od43vkVsU7wlapgLJ6419GHSDZ6/GUGPp4mN94uc/RsywbgTQhWQ8QKBJtDoUXOQzotT Z52GV1OujGBd6oM7AtgPNXNn4OZc1OWIXveFczUmlGeY5j9NnEVbaWzdZu9N3Jgjmnhk FRRExAaAS/02kRfnVEKPKdcxDnQl4BTWgTSu2pI5RcIkF7BlhU4Eh5APG1wm0wztYR0C hRo+sKgLLJB8QqGSNcJD9q7dU2C57DxD38yEK9cZ3o95tAFBaejL87C8mJuv9MJ6RCf6 WfyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181370; x=1694786170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; b=Ww4uMyeSb7qEGGetz/knG5HbZJB6lXaFeP0VeO+cTdBcfLgphtIefxlx33uRSZEJJx DOPf6m8th5Qx7uWsxIl9bEN9/0YTreu8xdGmDwch0gjcul06zgZkQdY/cg8dkorTOt/n Np1rsYpd9fqTsS7jsUoBIYHbEoKbyi+qwZBmFSXUwRa/PzG0mrU1upo0CJZllj50sDIs vipSHYRWAD/qCu8Eme+MuYWia1CC2rIQauAnRGpHsFL0iBRFFIQOx2KN9RGYNipR9J1w SgkaJJapjB/6tcK7EWbbwvOnqCD/Xlk/DUqsmgg0gKWS6gP7VLKfzRHfdsVGHpfYmCQv H3Wg== X-Gm-Message-State: AOJu0Yz0jocX/pswyQAWuVNHVLmgPNyEhM4yKVE8l2+F9HvfAiu5AW8g JgWkw+R8YlMkZqtzHrqON4Awk2QH8yj3QfBPja1xPg== X-Received: by 2002:a2e:9c83:0:b0:2bb:c19b:710c with SMTP id x3-20020a2e9c83000000b002bbc19b710cmr862975lji.5.1694181370123; Fri, 08 Sep 2023 06:56:10 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:09 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 15/15] net/lwip/wget add port selection Date: Fri, 8 Sep 2023 19:53:20 +0600 Message-Id: <20230908135320.7066-16-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Allow to specify HTTP port instead of just using default for wget command. Signed-off-by: Maxim Uvarov --- 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; }