host: Ignore spaces around - when parsing ranges

This commit is contained in:
Tobias Brunner
2014-10-30 12:32:45 +01:00
parent e0cd3bad3d
commit cd67cd70c8
3 changed files with 23 additions and 9 deletions
+14 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2012 Tobias Brunner
* Copyright (C) 2006-2014 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
@@ -530,19 +530,27 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
*/
bool host_create_from_range(char *string, host_t **from, host_t **to)
{
char *pos;
char *sep, *pos;
pos = strchr(string, '-');
if (!pos)
sep = strchr(string, '-');
if (!sep)
{
return FALSE;
}
*to = host_create_from_string(pos + 1, 0);
for (pos = sep+1; *pos && *pos == ' '; pos++)
{
/* trim spaces before to address*/
}
*to = host_create_from_string(pos, 0);
if (!*to)
{
return FALSE;
}
pos = strndup(string, pos - string);
for (pos = sep-1; pos > string && *pos == ' '; pos--)
{
/* trim spaces behind from address */
}
pos = strndup(string, pos - string + 1);
*from = host_create_from_string_and_family(pos, (*to)->get_family(*to), 0);
free(pos);
if (!*from)
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2009 Tobias Brunner
* Copyright (C) 2006-2014 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2008 Martin Willi
* Copyright (C) 2005 Jan Hutter