dhcpd-pools  3.0
ISC dhcpd lease usage analyser
Functions
sort.c File Reference

Functions to sort output. More...

#include <config.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
#include "progname.h"
#include "quote.h"
#include "xalloc.h"
#include "dhcpd-pools.h"
Include dependency graph for sort.c:

Functions

int ipcomp_init (const union ipaddr_t *restrict a __attribute__((unused)), const union ipaddr_t *restrict b __attribute__((unused)))
 Compare IP address, with IPv4/v6 determination. More...
 
int ipcomp_v4 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
 
int ipcomp_v6 (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b)
 
int leasecomp_init (const struct leases_t *restrict a __attribute__((unused)), const struct leases_t *restrict b __attribute__((unused)))
 Compare IP address in leases_t structure, with IPv4/v6 determination. More...
 
int leasecomp_v4 (const struct leases_t *restrict a, const struct leases_t *restrict b)
 
int leasecomp_v6 (const struct leases_t *restrict a, const struct leases_t *restrict b)
 
int rangecomp (const void *restrict r1, const void *restrict r2)
 Compare IP address in leases. More...
 
int comp_double (double f1, double f2)
 Compare two doubles. More...
 
int comp_ip (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their first_ip. More...
 
int comp_max (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their capacity. More...
 
int comp_cur (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their current usage. More...
 
int comp_percent (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their current usage percentage. More...
 
int comp_touched (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched addresses. More...
 
int comp_tc (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched and in use addresses. More...
 
int comp_tcperc (struct range_t *r1, struct range_t *r2)
 Compare two range_t by their touched and in use percentage. More...
 
double ret_percent (struct range_t r)
 Percentage in use in range. More...
 
double ret_tc (struct range_t r)
 Touched and in use in range. More...
 
double ret_tcperc (struct range_t r)
 Return percentage of addresses touched and in use in range. More...
 
comparer_t field_selector (char c)
 Sort field selector. More...
 
static int merge (struct conf_t *state, struct range_t *restrict left, struct range_t *restrict right)
 Perform requested sorting. More...
 
void mergesort_ranges (struct conf_t *state, struct range_t *restrict orig, unsigned int size, struct range_t *restrict temp, const int root_call)
 Mergesort for range table. More...
 

Detailed Description

Functions to sort output.

Function Documentation

◆ comp_cur()

int comp_cur ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ comp_double()

int comp_double ( double  f1,
double  f2 
)

Compare two doubles.

Parameters
f1,f2Data to compare.
Returns
Like strcmp.

Referenced by comp_cur(), comp_max(), comp_percent(), comp_tc(), comp_tcperc(), and comp_touched().

◆ comp_ip()

int comp_ip ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their first_ip.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

◆ comp_max()

int comp_max ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their capacity.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ comp_percent()

int comp_percent ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their current usage percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ comp_tc()

int comp_tc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ comp_tcperc()

int comp_tcperc ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched and in use percentage.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ comp_touched()

int comp_touched ( struct range_t r1,
struct range_t r2 
)

Compare two range_t by their touched addresses.

Parameters
r1,r2Pointers to data to compare.
Returns
Like strcmp.

Referenced by field_selector().

Here is the call graph for this function:

◆ field_selector()

comparer_t field_selector ( char  c)

Sort field selector.

Parameters
cSymbolic name of a sort by character. The sort algorithms are stabile, which means multiple sorts can be specified and they do not mess the result of previous sort. The sort algorithms are used via function pointer, that gets to be reassigned.
Returns
Return the selected compare function.

Referenced by parse_command_line_opts().

Here is the call graph for this function:

◆ ipcomp_init()

int ipcomp_init ( const union ipaddr_t *restrict a   __attribute__(unused),
const union ipaddr_t *restrict b   __attribute__(unused) 
)

Compare IP address, with IPv4/v6 determination.

Parameters
aBinary IP address.
bBinary IP address.
Returns
If a < b return -1, if a < b return 1, when they are equal return 0.

◆ ipcomp_v4()

int ipcomp_v4 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

◆ ipcomp_v6()

int ipcomp_v6 ( const union ipaddr_t *restrict  a,
const union ipaddr_t *restrict  b 
)

Referenced by set_ipv_functions().

◆ leasecomp_init()

int leasecomp_init ( const struct leases_t *restrict a   __attribute__(unused),
const struct leases_t *restrict b   __attribute__(unused) 
)

Compare IP address in leases_t structure, with IPv4/v6 determination.

Parameters
aBinary IP address.
bBinary IP address.
Returns
If a < b return -1, if a < b return 1, when they are equal return 0.

Referenced by set_ipv_functions().

◆ leasecomp_v4()

int leasecomp_v4 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

◆ leasecomp_v6()

int leasecomp_v6 ( const struct leases_t *restrict  a,
const struct leases_t *restrict  b 
)

Referenced by set_ipv_functions().

◆ merge()

static int merge ( struct conf_t state,
struct range_t *restrict  left,
struct range_t *restrict  right 
)
static

Perform requested sorting.

Parameters
leftThe left side of the merge sort.
rightThe right side of the merge sort.
Returns
Relevant for merge sort decision.

Referenced by mergesort_ranges().

◆ mergesort_ranges()

void mergesort_ranges ( struct conf_t state,
struct range_t *restrict  orig,
unsigned int  size,
struct range_t *restrict  temp,
const int  root_call 
)

Mergesort for range table.

Referenced by main().

Here is the call graph for this function:

◆ rangecomp()

int rangecomp ( const void *restrict  r1,
const void *restrict  r2 
)

Compare IP address in leases.

Suitable for sorting range table.

Parameters
r1A range structure.
r2A range structure.
Returns
Return pas through from ipcomp.

◆ ret_percent()

double ret_percent ( struct range_t  r)

Percentage in use in range.

Parameters
rA range structure.
Returns
Usage percentage of the given range.

Referenced by comp_percent().

◆ ret_tc()

double ret_tc ( struct range_t  r)

Touched and in use in range.

Parameters
rA range structure.
Returns
Number of touched or in use addresses in the given range.

Referenced by comp_tc(), and ret_tcperc().

◆ ret_tcperc()

double ret_tcperc ( struct range_t  r)

Return percentage of addresses touched and in use in range.

Parameters
rA range structure.
Returns
Percentage of touched or in use addresses in the given range.

Referenced by comp_tcperc().

Here is the call graph for this function: