diff options
author | Martin Willi <martin@revosec.ch> | 2010-10-29 09:54:15 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-01-05 16:45:40 +0100 |
commit | 65697c27345bdae19e5ca5d43ee15509e18b19ec (patch) | |
tree | ce692f36d1c1e32de6348d09c1c6445985c8b4ea /src/libstrongswan/utils/host.c | |
parent | 84f89634efdfd8d3eebcba3d0cfac3704ff8ec06 (diff) | |
download | strongswan-65697c27345bdae19e5ca5d43ee15509e18b19ec.tar.bz2 strongswan-65697c27345bdae19e5ca5d43ee15509e18b19ec.tar.xz |
Added a CIDR notation based host constructor
Diffstat (limited to 'src/libstrongswan/utils/host.c')
-rw-r--r-- | src/libstrongswan/utils/host.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/host.c b/src/libstrongswan/utils/host.c index 112d07e5c..50e43d992 100644 --- a/src/libstrongswan/utils/host.c +++ b/src/libstrongswan/utils/host.c @@ -564,6 +564,41 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port) /* * Described in header. */ +host_t *host_create_from_subnet(char *string, int *bits) +{ + char *pos, buf[64]; + host_t *net; + + pos = strchr(string, '/'); + if (pos) + { + if (pos - string >= sizeof(buf)) + { + return NULL; + } + strncpy(buf, string, pos - string); + buf[pos - string] = '\0'; + *bits = atoi(pos + 1); + return host_create_from_string(buf, 0); + } + net = host_create_from_string(buf, 0); + if (net) + { + if (net->get_family(net) == AF_INET) + { + *bits = 32; + } + else + { + *bits = 128; + } + } + return net; +} + +/* + * Described in header. + */ host_t *host_create_any(int family) { private_host_t *this = host_create_empty(); |