[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [PATCHv4 5/5] net/lwip: apps/http: add dns support
From: |
Maxim Uvarov |
Subject: |
[lwip-devel] [PATCHv4 5/5] net/lwip: apps/http: add dns support |
Date: |
Fri, 14 Jul 2023 20:20:00 +0600 |
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);
+ 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
- Re: [lwip-devel] [PATCHv4 1/5] net/lwip: add lwip-external submodule, (continued)
[lwip-devel] [PATCHv4 2/5] net/lwip: add lwip library for the network stack, Maxim Uvarov, 2023/07/14
[lwip-devel] [PATCHv4 4/5] net/lwip: add dns command, Maxim Uvarov, 2023/07/14
[lwip-devel] [PATCHv4 3/5] net/lwip: add doc/develop/net_lwip.rst, Maxim Uvarov, 2023/07/14
[lwip-devel] [PATCHv4 5/5] net/lwip: apps/http: add dns support,
Maxim Uvarov <=
Re: [lwip-devel] [PATCHv4 0/5] net/lwip: add lwip library for the network stack, Ilias Apalodimas, 2023/07/27
Re: [lwip-devel] [PATCHv4 0/5] net/lwip: add lwip library for the network stack, Simon Glass, 2023/07/28