From 82be444eb99b51f42e717bf883a981ae9cd7d77e Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 28 Oct 2014 18:14:29 +0100 Subject: host: Add function to create two hosts from a range definition --- src/libstrongswan/networking/host.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/libstrongswan/networking/host.c') diff --git a/src/libstrongswan/networking/host.c b/src/libstrongswan/networking/host.c index 8d04a4ec9..95c7390a7 100644 --- a/src/libstrongswan/networking/host.c +++ b/src/libstrongswan/networking/host.c @@ -525,6 +525,34 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port) return &this->public; } +/* + * Described in header. + */ +bool host_create_from_range(char *string, host_t **from, host_t **to) +{ + char *pos; + + pos = strchr(string, '-'); + if (!pos) + { + return FALSE; + } + *to = host_create_from_string(pos + 1, 0); + if (!*to) + { + return FALSE; + } + pos = strndup(string, pos - string); + *from = host_create_from_string_and_family(pos, (*to)->get_family(*to), 0); + free(pos); + if (!*from) + { + (*to)->destroy(*to); + return FALSE; + } + return TRUE; +} + /* * Described in header. */ -- cgit v1.2.3