diff options
Diffstat (limited to 'mdk-stage1/url.c')
| -rw-r--r-- | mdk-stage1/url.c | 17 | 
1 files changed, 14 insertions, 3 deletions
| diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index 3d2846649..14f1e25d6 100644 --- a/mdk-stage1/url.c +++ b/mdk-stage1/url.c @@ -398,9 +398,10 @@ char *str_ftp_error(int error)  } -static int _http_download_file(char * hostname, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion) +static int _http_download_file(char * hostport, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion)  {  	char * buf; +	char * hostname = strdup(hostport);  	char headers[4096];  	char * nextChar = headers;  	int statusCode; @@ -418,8 +419,15 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c  		http_server_name = proxyname;  		http_server_port = atoi(proxyport);  	} else { -		http_server_name = hostname; -		http_server_port = 80; +		char *port = strchr(hostname, ':'); +		if (port) { +			*port = '\0'; +			http_server_name = hostname; +			http_server_port = atoi(++port); +		} else { +			http_server_name = hostname; +			http_server_port = 80; +		}  	}		  	log_message("HTTP: connecting to server %s:%i (%s)", @@ -430,6 +438,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c  	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);  	if (sock < 0) { +		free(hostname);  		return FTPERR_FAILED_CONNECT;  	} @@ -439,6 +448,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c  	if (connect(sock, (struct sockaddr *) &destPort, sizeof(destPort))) {  		close(sock); +		free(hostname);  		return FTPERR_FAILED_CONNECT;  	} @@ -446,6 +456,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c                              : asprintf_("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", remotename, hostname);  	write(sock, buf, strlen(buf)); +	free(hostname);  	/* This is fun; read the response a character at a time until we: | 
