From patchwork Fri Jul 14 14:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 702726 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp1114380wrj; Fri, 14 Jul 2023 07:23:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlEOZUVQdckVZbesKG2mJ5GNMX5/FbxNiocJnpy3A1bXdKc8W1xdX8fpL/XJqkLvWWRx6n54 X-Received: by 2002:a05:6402:287:b0:51e:da3:1585 with SMTP id l7-20020a056402028700b0051e0da31585mr3663838edv.9.1689344602838; Fri, 14 Jul 2023 07:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689344602; cv=none; d=google.com; s=arc-20160816; b=dsTNUy1H8dKu/frJjBiB8qjY+zVloee6MROQm4vwkU0hgNH+pDekaBvBHzQymEQuHE 0PUdWwlRedvV+4CBvxdqYHdq4Eas/DQvcdcBXy0latnYL58rI5AoV5Er3aiWA6wi3s7R 2TBfrXbHePYWFZdE3OtmN9kNg97QA8ptq4RkU8xfMcuROJ4manSkhNucs34ERJBH8d21 LKXJXh7+R4CAzBkNR7rPO1jLGZp22o/vRrJSIItCT1bCT76jZukgrJLC7pCI4V/LZ0CD mUx/ZOi7yAiWQS6G4bIe2qn2EqLRpOXb33RNgHqPpn7XulWGxIj57tGRRfxtMFnhGOy/ e0yg== 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=uhHKOSp14TbQWgMLwoQOm7YiaKI8a4TZyyde6l3hn6o=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=Wz9tBOSMtzPJxVYWJESr3d/6ofSFamGec+NXMheOdbmoNqnIR9v1HAL/+/Nxja/xoB gKHAf1upbOif3bm6sbLG8ESEW3TddmTIlGlNhg8KvY5LVdHIlnQgyTom7P9GzwoEleFY fqglBf8ddgdIdISJixglUvsodmCZMYiLHyXH0jBxRlQFx/Yqi3Ds79l2D+OcW/4FCf15 MLlEKJbcFZL+2eHEHVYFWYRVSv5i5ghxuQapNUeR8gufm1SbbtDOHfDb2jwoxR3kh0wO qkdmO892sXHeoCbJKcCE/VLuISMLvMaxFtoAfW+6f6KCUAQhcXVk3wGMug+qhc7gVQ4g SLEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BlHxrmp1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id e22-20020aa7d7d6000000b0051de5968bd8si8900008eds.443.2023.07.14.07.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 07:23:22 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BlHxrmp1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 1554E86DC8; Fri, 14 Jul 2023 16:22:35 +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="BlHxrmp1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66BE886DBA; Fri, 14 Jul 2023 16:22:29 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) (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 F22C886D20 for ; Fri, 14 Jul 2023 16:22:26 +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-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f954d7309fso2394279e87.1 for ; Fri, 14 Jul 2023 07:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689344546; x=1691936546; 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=uhHKOSp14TbQWgMLwoQOm7YiaKI8a4TZyyde6l3hn6o=; b=BlHxrmp1A2PUIo3S/CZU2mAD83Cv4IfyuGgMFZEnaWjEp4CHdZc5rfmcj0uehOdUL6 HOJ0PUCy7NgylBO23LgTTfrHgtBbvfqAc5YJC8DTP/SsfewWwJhfi7skJI4E4p+AZ/Nw dBqIsWrjaO8CWfc3gXb9D+SW1Z/zpQ1IlhaFssHKob7zrVoVdh0kk6ZQ1RIHP8Y+l1Gn yplDVzWesDBpk+1ijHf7gHvj2dKR7HWDN3EgcmR7GdFsS0aSs8w6L2CIAeTrtPfyucYQ m3EN9KNusbKIWyuKl6RV7LCfs00dFS9u070p8YW9W/V88kxCHxgBrSI6YED3krY19gRU nL4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689344546; x=1691936546; 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=uhHKOSp14TbQWgMLwoQOm7YiaKI8a4TZyyde6l3hn6o=; b=hx5SI1JmHCltNgk4gFzDJttyH2WaPsHWauQmJRQ0Rn+ZynwJJk/tc74ZgOHyz0PlDe Kfa++g/2G6wQq+s4za+SSCTcwjDdSBaI9OOwYtp29DLFJMpPLwD696MX9N8IiYUrSjUy 8HcfzNm1FSNIAfG9YcgEffjSYtglcN9Hw3Tl+64DEPHdKz5qwI0w6RMlLMo5q83trtaJ JzQVXZlDFxJrzmWdysfnc7kHhWcCTWuq/H22w+dX3SpHJNtPrHdrvf76bVIqDeoIcVNi Pd6cBL3VbGNsO6xLirg9eZI6drOEvJ8fNel7omlvnjnJa2HVmaZgxv3C0zwE0KMes2Df 8XDQ== X-Gm-Message-State: ABy/qLZPNmjij07lcQ4BneNsY4NwmlArl+9Q0dQKcHYA6zqsPB4hN/IL ZJlwaedWgiiG/vHYL6iCuxHeleTqAJhKehtCB/9zLA== X-Received: by 2002:a05:6512:6d4:b0:4f8:5e4e:52ad with SMTP id u20-20020a05651206d400b004f85e4e52admr883332lff.23.1689344546046; Fri, 14 Jul 2023 07:22:26 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id w28-20020ac2599c000000b004fb759964a9sm1504703lfn.168.2023.07.14.07.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 07:22:25 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv4 5/5] net/lwip: apps/http: add dns support Date: Fri, 14 Jul 2023 20:20:00 +0600 Message-Id: <20230714142000.5534-6-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230714142000.5534-1-maxim.uvarov@linaro.org> References: <20230714142000.5534-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 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); + 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);