mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-07 00:01:49 -04:00
Added a CIDR notation based host constructor
This commit is contained in:
parent
84f89634ef
commit
65697c2734
@ -561,6 +561,41 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
@ -189,6 +189,15 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
|
||||
*/
|
||||
host_t *host_create_from_sockaddr(sockaddr_t *sockaddr);
|
||||
|
||||
/**
|
||||
* Create a host from a CIDR subnet definition (1.2.3.0/24), return bits.
|
||||
*
|
||||
* @param string string to parse
|
||||
* @param bits gets the number of network bits in CIDR notation
|
||||
* @return network start address, NULL on error
|
||||
*/
|
||||
host_t *host_create_from_subnet(char *string, int *bits);
|
||||
|
||||
/**
|
||||
* Create a host without an address, a "any" host.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user