From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cVp62-0002c8-8J for mharc-grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVp5z-0002aS-I1 for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVp5y-0000z1-NR for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:23 -0500 Received: from cavan.codon.org.uk ([2a00:1098:0:80:1000:c:0:1]:56354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVp5y-0000yW-HE for grub-devel@gnu.org; Mon, 23 Jan 2017 19:36:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codon.org.uk; s=63138784; h=Subject:References:In-Reply-To:Message-Id:Date:Cc:To:From; bh=yAX2AQmL3+V5t+63a81oahRNj+x+w/8rHo/cwzsEcXc=; b=rDQh78M4yYRg9g+4rfxZ/6XV+XQNVA2KHlpy+hL3b/7ZnZuXMUS3M/Pr4aEqzZNjqidTU4Axc1TJcR1vkDBgirEHPfzaYiTTbRQoowvkfPEo7eFcH3MMmdC7tingq2AwaxQoMHxE308zPAdrDX58F3lHf7NR8PyDctdq2dRdk+A=; Received: from [2603:3024:1c06:3af3:3252:cbff:fee6:e579] (helo=xps13-mjg59.libcore.so) by cavan.codon.org.uk with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1cVp5s-0002Sb-Tb; Tue, 24 Jan 2017 00:36:19 +0000 From: Matthew Garrett To: grub-devel@gnu.org Cc: Matthew Garrett Date: Mon, 23 Jan 2017 16:35:58 -0800 Message-Id: <20170124003601.24612-2-mjg59@coreos.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170124003601.24612-1-mjg59@coreos.com> References: <20170124003601.24612-1-mjg59@coreos.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 2603:3024:1c06:3af3:3252:cbff:fee6:e579 X-SA-Exim-Mail-From: mjg59@codon.org.uk Subject: [PATCH 1/4] Allow non-default ports for HTTP requests X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:54:46 +0000) X-SA-Exim-Scanned: Yes (on cavan.codon.org.uk) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a00:1098:0:80:1000:c:0:1 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2017 00:36:24 -0000 Add support for passing ports in HTTP requests. This takes the form of: (http,serverip:portnum)/file --- grub-core/net/http.c | 8 ++++++-- grub-core/net/net.c | 10 +++++++++- include/grub/net.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/grub-core/net/http.c b/grub-core/net/http.c index 5aa4ad3..389a78e 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -309,7 +309,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) { http_data_t data = file->data; grub_uint8_t *ptr; - int i; + int i, port; struct grub_net_buff *nb; grub_err_t err; @@ -390,8 +390,12 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) grub_netbuff_put (nb, 2); grub_memcpy (ptr, "\r\n", 2); + if (file->device->net->port) + port = file->device->net->port; + else + port = HTTP_PORT; data->sock = grub_net_tcp_open (file->device->net->server, - HTTP_PORT, http_receive, + port, http_receive, http_err, http_err, file); if (!data->sock) diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 10773fc..585f4f7 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1261,7 +1261,7 @@ grub_net_open_real (const char *name) grub_net_app_level_t proto; const char *protname, *server; grub_size_t protnamelen; - int try; + int try, port = 0; if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) { @@ -1278,7 +1278,14 @@ grub_net_open_real (const char *name) else { const char *comma; + char *colon; comma = grub_strchr (name, ','); + colon = grub_strchr (name, ':'); + if (colon) + { + port = (int) grub_strtol(colon+1, NULL, 10); + *colon = '\0'; + } if (comma) { protnamelen = comma - name; @@ -1310,6 +1317,7 @@ grub_net_open_real (const char *name) if (!ret) return NULL; ret->protocol = proto; + ret->port = port; ret->server = grub_strdup (server); if (!ret->server) { diff --git a/include/grub/net.h b/include/grub/net.h index 2192fa1..c517509 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -276,6 +276,7 @@ typedef struct grub_net grub_fs_t fs; int eof; int stall; + int port; } *grub_net_t; extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); -- 2.9.3