dhcpd-pools  3.0
ISC dhcpd lease usage analyser
Macros | Functions | Variables
other.c File Reference

Collection of various functions. More...

#include <config.h>
#include <arpa/inet.h>
#include <errno.h>
#include <limits.h>
#include <netinet/in.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "error.h"
#include "progname.h"
#include "quote.h"
#include "xalloc.h"
#include "dhcpd-pools.h"
Include dependency graph for other.c:

Macros

#define stringify(s)   #s
 
#define stringify_value(s)   stringify(s)
 

Functions

static char * cidr_last_v4 (union ipaddr_t *restrict addr, const int mask)
 Find last address in IPv4 range by using cidr format. More...
 
static char * cidr_last_v6 (union ipaddr_t *restrict addr, const int mask)
 Find last address in IPv6 range by using cidr format. More...
 
void set_ipv_functions (struct conf_t *state, int version)
 Set function pointers depending on IP version. More...
 
int parse_ipaddr_init (struct conf_t *state, const char *restrict src, union ipaddr_t *restrict dst)
 Convert text string IP address from either IPv4 or IPv6 to an integer. More...
 
int parse_ipaddr_v4 (struct conf_t *state __attribute__((unused)), const char *restrict src, union ipaddr_t *restrict dst)
 
int parse_ipaddr_v6 (struct conf_t *state __attribute__((unused)), const char *restrict src, union ipaddr_t *restrict dst)
 
static int strtol_mask (const char *str)
 Convert string to a desimal format network marks. More...
 
void parse_cidr (struct conf_t *state, struct range_t *range_p, const char *word)
 Convert a cidr notated address to a range. More...
 
void copy_ipaddr_init (union ipaddr_t *restrict dst __attribute__((unused)), const union ipaddr_t *restrict src __attribute__((unused)))
 Copy IP address to union. More...
 
void copy_ipaddr_v4 (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src)
 
void copy_ipaddr_v6 (union ipaddr_t *restrict dst, const union ipaddr_t *restrict src)
 
const char * ntop_ipaddr_init (const union ipaddr_t *ip __attribute__((unused)))
 Convert an address to string. More...
 
const char * ntop_ipaddr_v4 (const union ipaddr_t *ip)
 
const char * ntop_ipaddr_v6 (const union ipaddr_t *ip)
 
double get_range_size_init (const struct range_t *r __attribute__((unused)))
 Calculate how many addresses there are in a range. More...
 
double get_range_size_v4 (const struct range_t *r)
 
double get_range_size_v6 (const struct range_t *r)
 
int xstrstr_init (struct conf_t *state, const char *restrict str)
 
int xstrstr_v4 (struct conf_t *state __attribute__((unused)), const char *restrict str)
 
int xstrstr_v6 (struct conf_t *state __attribute__((unused)), const char *restrict str)
 
int parse_color_mode (const char *restrict optarg)
 Parse option argument color mode. More...
 
double strtod_or_err (const char *restrict str, const char *restrict errmesg)
 Return a double floating point value. More...
 
void flip_ranges (struct conf_t *state)
 Reverse range. More...
 
void clean_up (struct conf_t *state)
 Free memory, flush buffers etc. More...
 
void dp_time_tool (FILE *file, const char *path, int epoch)
 Print a time stamp of a path or now to output file. More...
 
void __attribute__ ((__noreturn__))
 A version printing. More...
 

Variables

char *(* cidr_last )(union ipaddr_t *restrict addr, const int mask)
 

Detailed Description

Collection of various functions.

Macro Definition Documentation

◆ stringify

#define stringify (   s)    #s

◆ stringify_value

#define stringify_value (   s)    stringify(s)

Referenced by __attribute__().

Function Documentation

◆ __attribute__()

void __attribute__ ( (__noreturn__)  )

A version printing.

Command line help screen.

Referenced by xstrstr_init(), and xstrstr_v4().

◆ cidr_last_v4()

static char * cidr_last_v4 ( union ipaddr_t *restrict  addr,
const int  mask 
)
static

Find last address in IPv4 range by using cidr format.

Parameters
addrPointer to memory where address needs to be stored.
Returns
Allocated string format of the address.

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ cidr_last_v6()

static char * cidr_last_v6 ( union ipaddr_t *restrict  addr,
const int  mask 
)
static

Find last address in IPv6 range by using cidr format.

Parameters
addrPointer to memory where address needs to be stored.
Returns
Allocated string format of the address.

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ clean_up()

void clean_up ( struct conf_t state)

Free memory, flush buffers etc.

Referenced by main().

Here is the call graph for this function:

◆ copy_ipaddr_init()

void copy_ipaddr_init ( union ipaddr_t *restrict dst   __attribute__(unused),
const union ipaddr_t *restrict src   __attribute__(unused) 
)

Copy IP address to union.

Parameters
dstDestination for a binary IP address.
srcSourse of an IP address.

Referenced by set_ipv_functions().

◆ copy_ipaddr_v4()

void copy_ipaddr_v4 ( union ipaddr_t *restrict  dst,
const union ipaddr_t *restrict  src 
)

Referenced by set_ipv_functions().

◆ copy_ipaddr_v6()

void copy_ipaddr_v6 ( union ipaddr_t *restrict  dst,
const union ipaddr_t *restrict  src 
)

Referenced by set_ipv_functions().

◆ dp_time_tool()

void dp_time_tool ( FILE *  file,
const char *  path,
int  epoch 
)

Print a time stamp of a path or now to output file.

Referenced by html_header(), must_put_base(), must_put_range(), must_put_shnet(), and output_json().

Here is the call graph for this function:

◆ flip_ranges()

void flip_ranges ( struct conf_t state)

Reverse range.

Used before output, if a caller has requested reverse sorting.

Referenced by main().

Here is the call graph for this function:

◆ get_range_size_init()

double get_range_size_init ( const struct range_t *r   __attribute__(unused))

Calculate how many addresses there are in a range.

Parameters
rPointer to range structure, which has information about first and last IP in the range.
Returns
Size of a range.

Referenced by set_ipv_functions().

◆ get_range_size_v4()

double get_range_size_v4 ( const struct range_t r)

Referenced by set_ipv_functions().

◆ get_range_size_v6()

double get_range_size_v6 ( const struct range_t r)

Referenced by set_ipv_functions().

◆ ntop_ipaddr_init()

const char* ntop_ipaddr_init ( const union ipaddr_t *ip   __attribute__(unused))

Convert an address to string.

This function will convert the IPv4 addresses to 123.45.65.78 format, and the IPv6 addresses to it's native format depending on which version of the addressing is found to be in use.

Parameters
ipBinary IP address.
Returns
Printable address.

Referenced by set_ipv_functions().

◆ ntop_ipaddr_v4()

const char* ntop_ipaddr_v4 ( const union ipaddr_t ip)

Referenced by set_ipv_functions().

◆ ntop_ipaddr_v6()

const char* ntop_ipaddr_v6 ( const union ipaddr_t ip)

Referenced by set_ipv_functions().

◆ parse_cidr()

void parse_cidr ( struct conf_t state,
struct range_t range_p,
const char *  word 
)

Convert a cidr notated address to a range.

Parameters
range_pPointer to memory where addresses need to be stored.
wordA range as a cidr string.

Referenced by parse_config().

Here is the call graph for this function:

◆ parse_color_mode()

int parse_color_mode ( const char *restrict  optarg)

Parse option argument color mode.

Parameters
Colormode string.
Returns
color mode enum.

Referenced by parse_command_line_opts().

◆ parse_ipaddr_init()

int parse_ipaddr_init ( struct conf_t state,
const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Convert text string IP address from either IPv4 or IPv6 to an integer.

Parameters
srcAn IP string in either format.
dstAn union which will hold conversion result.
Returns
Was parsing successful.

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ parse_ipaddr_v4()

int parse_ipaddr_v4 ( struct conf_t *state   __attribute__(unused),
const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Referenced by set_ipv_functions().

◆ parse_ipaddr_v6()

int parse_ipaddr_v6 ( struct conf_t *state   __attribute__(unused),
const char *restrict  src,
union ipaddr_t *restrict  dst 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ set_ipv_functions()

void set_ipv_functions ( struct conf_t state,
int  version 
)

Set function pointers depending on IP version.

Parameters
ipIP version.

Referenced by main(), parse_cidr(), parse_command_line_opts(), parse_ipaddr_init(), and xstrstr_init().

Here is the call graph for this function:

◆ strtod_or_err()

double strtod_or_err ( const char *restrict  str,
const char *restrict  errmesg 
)

Return a double floating point value.

Parameters
strString to be converted to a double.
errmesgExit error message if conversion fails.
Returns
Binary result of string to double conversion.

Referenced by parse_command_line_opts().

Here is the call graph for this function:

◆ strtol_mask()

static int strtol_mask ( const char *  str)
static

Convert string to a desimal format network marks.

Parameters
srcDigit that should be a network mask.
Returns
Network mask, or -1 when failing.

Referenced by parse_cidr().

◆ xstrstr_init()

int xstrstr_init ( struct conf_t state,
const char *restrict  str 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ xstrstr_v4()

int xstrstr_v4 ( struct conf_t *state   __attribute__(unused),
const char *restrict  str 
)

Referenced by set_ipv_functions().

Here is the call graph for this function:

◆ xstrstr_v6()

int xstrstr_v6 ( struct conf_t *state   __attribute__(unused),
const char *restrict  str 
)

Referenced by set_ipv_functions().

Variable Documentation

◆ cidr_last

char*(* cidr_last) (union ipaddr_t *restrict addr, const int mask)

Referenced by parse_cidr(), and set_ipv_functions().