From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01994C04A6A for ; Thu, 27 Jul 2023 12:59:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C440F8676D; Thu, 27 Jul 2023 14:59:24 +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="AfA/gtHo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5F9A186604; Thu, 27 Jul 2023 14:59:22 +0200 (CEST) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 52443867EF for ; Thu, 27 Jul 2023 14:59:19 +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=ilias.apalodimas@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso10272515e9.3 for ; Thu, 27 Jul 2023 05:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690462759; x=1691067559; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cOhNAQnlejztuhepBudniV/yT602V+aFsVjyyDWgC9U=; b=AfA/gtHomHn+mHSA3QUz6BVuzLYUZmo8QnS7IKIoE03+jJDON0nywm+hDqK8KR6Tca jUjgIK/4rUrHrgs790F4RftK34JdLKON65xaQn23tQST+wk2tAbAUX70DK0Yzk98eLFA JkVhC3x5MqyXMSDVJ1HVug/y7JMawz+yz3fVxpM+yOmMp18pkL3IMqaVz+R6voq2TCoe 4sSyK7oQNDE+a5cVagoNE7Wkh98cn1TMQw9veRqEKb3UfT7LZvpawC7TaKLs4hPnBdLt mJfwBr7dNiU0dxIkYxHpfdkv/VK2d0FNkCDkpv43xo0wJRwkzIM/g2WrprJM7fioYquj NZIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690462759; x=1691067559; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cOhNAQnlejztuhepBudniV/yT602V+aFsVjyyDWgC9U=; b=LcJCTzC9varkjm9eavCoB11cQ/fBMWH1RJXWVmE4T+X9hTgBHAMc3RNFsBWTZx8nOv QFc+hkib0zAIqySMHZ7hLNEGKy/dP/y2A51haMs98X9XZPxhU1zto/QTN3MC2EbraK+M Xp5nSrQQKUiDwgDSctX9wH9FaGDWlomVo/XsBzpa9xeqhb/dMCNTTo6TMeSVpkdBox0A LGTMzSajr6YLqKeyPvd+WjIBcIEKhdxWeBD1dGnyYAmw0XhxoSa4Y3ewLRjXfF8Ui+SG Ln+u++hISK7vNAs/N23S3bXBHqI1LQacJFDmoFnf2aBW9OFOj71z2mYXjAAIeNsbpFAv SJLw== X-Gm-Message-State: ABy/qLZk+VxepiJ5KmlPJZbP9F7Z2qOSbTDy33SdrJ+mTjdFu7lEFDZg sx2FlMqVkqib4gPgQlvcK6q1Hg== X-Google-Smtp-Source: APBJJlFJrVrI8PkhYmOeMbx6CBt0rIY3cfVBMcuVSJfNSYqBucseUL2+UBDN4wmCgWNdDiTW7B2zpw== X-Received: by 2002:a5d:4a8e:0:b0:314:1483:d8ad with SMTP id o14-20020a5d4a8e000000b003141483d8admr1949547wrq.44.1690462758635; Thu, 27 Jul 2023 05:59:18 -0700 (PDT) Received: from hades (ppp089210088142.access.hol.gr. [89.210.88.142]) by smtp.gmail.com with ESMTPSA id k17-20020adfe8d1000000b003143867d2ebsm2013406wrn.63.2023.07.27.05.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 05:59:18 -0700 (PDT) Date: Thu, 27 Jul 2023 15:59:15 +0300 From: Ilias Apalodimas To: Maxim Uvarov 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 Message-ID: References: <20230714142000.5534-1-maxim.uvarov@linaro.org> <20230714142000.5534-6-maxim.uvarov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230714142000.5534-6-maxim.uvarov@linaro.org> 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 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 > --- > 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 >