Terminate IPs resolved externally as expected
This commit is contained in:
@@ -58,12 +58,12 @@ struct url
|
||||
static int
|
||||
try_url(struct url *url, fko_cli_options_t *options)
|
||||
{
|
||||
int sock=-1, sock_success=0, res, error, http_buf_len;
|
||||
int sock=-1, sock_success=0, i, res, error, http_buf_len;
|
||||
int bytes_read = 0, position = 0;
|
||||
struct addrinfo *result=NULL, *rp, hints;
|
||||
char http_buf[HTTP_MAX_REQUEST_LEN] = {0};
|
||||
char http_response[HTTP_MAX_RESPONSE_LEN] = {0};
|
||||
char *ndx;
|
||||
char *ndx, c;
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA wsa_data;
|
||||
@@ -196,10 +196,21 @@ try_url(struct url *url, fko_cli_options_t *options)
|
||||
}
|
||||
ndx += 4;
|
||||
|
||||
/* Try to parse the content as an IP address.
|
||||
* Note: We are expecting the content to be exactly that
|
||||
* (possibly followed by whitespace or other not-digit value).
|
||||
/* Walk along the content to try to find the end of the IP address.
|
||||
* Note: We are expecting the content to be just an IP address
|
||||
* (possibly followed by whitespace or other not-digit value).
|
||||
*/
|
||||
for(i=0; i<MAX_IPV46_STR_LEN; i++) {
|
||||
c = *(ndx+i);
|
||||
if(! isdigit((int)(unsigned char)c) && ! ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) && c != '.' && c != ':')
|
||||
break;
|
||||
}
|
||||
|
||||
/* Terminate at the first non-digit and non-dot.
|
||||
*/
|
||||
*(ndx+i) = '\0';
|
||||
|
||||
/* Try to parse the content as an IP address. */
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME;
|
||||
|
||||
Reference in New Issue
Block a user