fixed IP range to subnet conversion in ts_to_subnet()
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <utils/linked_list.h>
|
#include <utils/linked_list.h>
|
||||||
#include <utils/identification.h>
|
#include <utils/identification.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#define NON_SUBNET_ADDRESS_RANGE 255
|
#define NON_SUBNET_ADDRESS_RANGE 255
|
||||||
|
|
||||||
@@ -599,7 +600,7 @@ static void to_subnet(private_traffic_selector_t *this, host_t **net, u_int8_t *
|
|||||||
* be anything else but a subnet. We use from_addr as subnet
|
* be anything else but a subnet. We use from_addr as subnet
|
||||||
* and try to calculate a usable subnet mask.
|
* and try to calculate a usable subnet mask.
|
||||||
*/
|
*/
|
||||||
int family, byte;
|
int family, non_zero_bytes;
|
||||||
u_int16_t port = 0;
|
u_int16_t port = 0;
|
||||||
chunk_t net_chunk;
|
chunk_t net_chunk;
|
||||||
|
|
||||||
@@ -622,12 +623,12 @@ static void to_subnet(private_traffic_selector_t *this, host_t **net, u_int8_t *
|
|||||||
}
|
}
|
||||||
|
|
||||||
net_chunk.ptr = malloc(net_chunk.len);
|
net_chunk.ptr = malloc(net_chunk.len);
|
||||||
memcpy(net_chunk.ptr, this->from, net_chunk.len);
|
memset(net_chunk.ptr, 0x00, net_chunk.len);
|
||||||
|
if (*mask)
|
||||||
for (byte = net_chunk.len - 1; byte >= (*mask / 8); --byte)
|
|
||||||
{
|
{
|
||||||
int shift = (byte + 1) * 8 - *mask;
|
non_zero_bytes = (*mask + 7) / 8;
|
||||||
net_chunk.ptr[byte] = net_chunk.ptr[byte] & (0xFF << shift);
|
memcpy(net_chunk.ptr, this->from, non_zero_bytes);
|
||||||
|
net_chunk.ptr[non_zero_bytes-1] &= 0xFF << (8 * non_zero_bytes - *mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->to_port == this->from_port)
|
if (this->to_port == this->from_port)
|
||||||
|
|||||||
Reference in New Issue
Block a user