From 29512bd8ec16f47db568694ec172075412ca115d Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 3 Aug 2012 21:49:03 -0400 Subject: [PATCH] [client] -R http recv() read until close (Jonathan Schulz) Applied patch from Jonathan Schulz to ensure that the fwknop client reads all data from a remote webserver when resolving the client IP address in -R mode. Jonathan indicated that some webservers would transfer HTTP headers and data separately, and a single recv() would therefore fail to get the necessary IP information. --- client/http_resolve_host.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/http_resolve_host.c b/client/http_resolve_host.c index 8a117b5c..aaae946e 100644 --- a/client/http_resolve_host.c +++ b/client/http_resolve_host.c @@ -132,6 +132,7 @@ int resolve_ip_http(fko_cli_options_t *options) { int sock, res, error, http_buf_len, i; + int bytes_read = 0, position = 0; int o1, o2, o3, o4; struct addrinfo *result, *rp, hints; struct url url; @@ -228,7 +229,17 @@ resolve_ip_http(fko_cli_options_t *options) ); } - res = recv(sock, http_response, HTTP_MAX_RESPONSE_LEN, 0); + do + { + memset(http_buf, 0, sizeof(http_buf)); + bytes_read = recv(sock, http_buf, sizeof(http_buf), 0); + if ( bytes_read > 0 ) { + memcpy(&http_response[position], http_buf, bytes_read); + position += bytes_read; + } + } + while ( bytes_read > 0 ); + http_response[HTTP_MAX_RESPONSE_LEN-1] = '\0'; #ifdef WIN32