mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 16:26:59 +00:00
various: split functions to IPv4 and IPv6 versions
The code selection will be set with function pointer, which avoids numerous IP version checks. As a result with some inputs the analysis runs quicker. Most users will not notice much of difference. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
97c6f0292f
commit
8da98bbc89
5 changed files with 215 additions and 89 deletions
29
src/sort.c
29
src/sort.c
|
|
@ -54,17 +54,26 @@
|
|||
* \param b Binary IP address.
|
||||
* \return If a < b return -1, if a < b return 1, when they are equal return 0.
|
||||
*/
|
||||
int ipcomp(const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
|
||||
int ipcomp_init(const union ipaddr_t *restrict a __attribute__((unused)),
|
||||
const union ipaddr_t *restrict b __attribute__((unused)))
|
||||
{
|
||||
if (config.dhcp_version == VERSION_6) {
|
||||
return memcmp(&a->v6, &b->v6, sizeof(a->v6));
|
||||
} else {
|
||||
if (a->v4 < b->v4)
|
||||
return -1;
|
||||
if (a->v4 > b->v4)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ipcomp_v4(const union ipaddr_t *restrict a,
|
||||
const union ipaddr_t *restrict b)
|
||||
{
|
||||
if (a->v4 < b->v4)
|
||||
return -1;
|
||||
if (a->v4 > b->v4)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ipcomp_v6(const union ipaddr_t *restrict a,
|
||||
const union ipaddr_t *restrict b)
|
||||
{
|
||||
return memcmp(&a->v6, &b->v6, sizeof(a->v6));
|
||||
}
|
||||
|
||||
/*! \brief Compare IP address in leases. Suitable for sorting range table.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue