Defines | Functions
util.c File Reference

Go to the source code of this file.

Defines

#define LDNS_MOD(x, y)   (((x) % (y) < 0) ? ((x) % (y) + (y)) : ((x) % (y)))
#define LDNS_DIV(x, y)   (((x) % (y) < 0) ? ((x) / (y) - 1 ) : ((x) / (y)))

Functions

ldns_lookup_tableldns_lookup_by_name (ldns_lookup_table *table, const char *name)
ldns_lookup_tableldns_lookup_by_id (ldns_lookup_table *table, int id)
int ldns_get_bit (uint8_t bits[], size_t index)
 Returns the value of the specified bit The bits are counted from left to right, so bit #0 is the left most bit.
int ldns_get_bit_r (uint8_t bits[], size_t index)
 Returns the value of the specified bit The bits are counted from right to left, so bit #0 is the right most bit.
void ldns_set_bit (uint8_t *byte, int bit_nr, bool value)
int ldns_hexdigit_to_int (char ch)
 Returns the int value of the given (hex) digit.
char ldns_int_to_hexdigit (int i)
 Returns the char (hex) representation of the given int.
int ldns_hexstring_to_data (uint8_t *data, const char *str)
 Converts a hex string to binary data.
const char * ldns_version (void)
 Show the internal library version.
time_t ldns_mktime_from_utc (const struct tm *tm)
 Convert TM to seconds since epoch (midnight, January 1st, 1970).
time_t mktime_from_utc (const struct tm *tm)
struct tm * ldns_serial_arithmitics_gmtime_r (int32_t time, time_t now, struct tm *result)
 The function interprets time as the number of seconds since epoch with respect to now using serial arithmitics (rfc1982).
int ldns_init_random (FILE *fd, unsigned int size)
 Init the random source applications should call this if they need entropy data within ldns If openSSL is available, it is automatically seeded from /dev/urandom or /dev/random.
uint16_t ldns_get_random (void)
 Get random number.
char * ldns_bubblebabble (uint8_t *data, size_t len)
 Encode data as BubbleBabble.
int ldns_b32_ntop (const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
int ldns_b32_ntop_extended_hex (const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
int b32_ntop (const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
int b32_ntop_extended_hex (const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
int ldns_b32_pton (const char *src, size_t src_sz, uint8_t *dst, size_t dst_sz)
int ldns_b32_pton_extended_hex (const char *src, size_t src_sz, uint8_t *dst, size_t dst_sz)
int b32_pton (const char *src, size_t src_sz, uint8_t *dst, size_t dst_sz)
int b32_pton_extended_hex (const char *src, size_t src_sz, uint8_t *dst, size_t dst_sz)

Define Documentation

#define LDNS_MOD (   x,
 
)    (((x) % (y) < 0) ? ((x) % (y) + (y)) : ((x) % (y)))

Definition at line 170 of file util.c.

#define LDNS_DIV (   x,
 
)    (((x) % (y) < 0) ? ((x) / (y) - 1 ) : ((x) / (y)))

Definition at line 171 of file util.c.


Function Documentation

ldns_lookup_table* ldns_lookup_by_name ( ldns_lookup_table table,
const char *  name 
)

Definition at line 30 of file util.c.

References ldns_struct_lookup_table::name.

Definition at line 41 of file util.c.

References ldns_struct_lookup_table::id, and ldns_struct_lookup_table::name.

int ldns_get_bit ( uint8_t  bits[],
size_t  index 
)

Returns the value of the specified bit The bits are counted from left to right, so bit #0 is the left most bit.

Parameters:
[in]bitsarray holding the bits
[in]indexto the wanted bit
Returns:

Definition at line 52 of file util.c.

int ldns_get_bit_r ( uint8_t  bits[],
size_t  index 
)

Returns the value of the specified bit The bits are counted from right to left, so bit #0 is the right most bit.

Parameters:
[in]bitsarray holding the bits
[in]indexto the wanted bit
Returns:
1 or 0 depending no the bit state

Definition at line 62 of file util.c.

void ldns_set_bit ( uint8_t *  byte,
int  bit_nr,
bool  value 
)

Definition at line 72 of file util.c.

int ldns_hexdigit_to_int ( char  ch)

Returns the int value of the given (hex) digit.

Parameters:
[in]chthe hex char to convert
Returns:
the converted decimal value

Definition at line 88 of file util.c.

char ldns_int_to_hexdigit ( int  ch)

Returns the char (hex) representation of the given int.

Parameters:
[in]chthe int to convert
Returns:
the converted hex char

Definition at line 113 of file util.c.

int ldns_hexstring_to_data ( uint8_t *  data,
const char *  str 
)

Converts a hex string to binary data.

Parameters:
[out]dataThe binary result is placed here. At least strlen(str)/2 bytes should be allocated
[in]strThe hex string to convert. This string should not contain spaces
Returns:
The number of bytes of converted data, or -1 if one of the arguments * is NULL, or -2 if the string length is not an even number

Definition at line 138 of file util.c.

References ldns_hexdigit_to_int().

const char* ldns_version ( void  )

Show the internal library version.

Returns:
a string with the version in it

Definition at line 160 of file util.c.

References LDNS_VERSION.

time_t ldns_mktime_from_utc ( const struct tm *  tm)

Convert TM to seconds since epoch (midnight, January 1st, 1970).

Like timegm(3), which is not always available.

Parameters:
[in]tma struct tm* with the date
Returns:
the seconds since epoch

Definition at line 194 of file util.c.

time_t mktime_from_utc ( const struct tm *  tm)

Definition at line 219 of file util.c.

References ldns_mktime_from_utc().

struct tm* ldns_serial_arithmitics_gmtime_r ( int32_t  time,
time_t  now,
struct tm *  result 
) [read]

The function interprets time as the number of seconds since epoch with respect to now using serial arithmitics (rfc1982).

That number of seconds is then converted to broken-out time information. This is especially usefull when converting the inception and expiration fields of RRSIG records.

Parameters:
[in]timenumber of seconds since epoch (midnight, January 1st, 1970) to be intepreted as a serial arithmitics number relative to now.
[in]nownumber of seconds since epoch (midnight, January 1st, 1970) to which the time value is compared to determine the final value.
[out]resultthe struct with the broken-out time information
Returns:
result on success or NULL on error

Definition at line 304 of file util.c.

int ldns_init_random ( FILE *  fd,
unsigned int  size 
)

Init the random source applications should call this if they need entropy data within ldns If openSSL is available, it is automatically seeded from /dev/urandom or /dev/random.

Seed the random function.

If you need more entropy, or have no openssl available, this function MUST be called at the start of the program

If openssl *is* available, this function just adds more entropy

Definition at line 327 of file util.c.

References LDNS_FREE, and LDNS_XMALLOC.

uint16_t ldns_get_random ( void  )

Get random number.

Returns:
random number.

Definition at line 400 of file util.c.

char* ldns_bubblebabble ( uint8_t *  data,
size_t  len 
)

Encode data as BubbleBabble.

Parameters:
[in]dataa pointer to data to be encoded
[in]lensize the number of bytes of data
Returns:
a string of BubbleBabble

Definition at line 418 of file util.c.

References LDNS_XMALLOC.

int ldns_b32_ntop ( const uint8_t *  src,
size_t  src_sz,
char *  dst,
size_t  dst_sz 
)

Definition at line 582 of file util.c.

int ldns_b32_ntop_extended_hex ( const uint8_t *  src,
size_t  src_sz,
char *  dst,
size_t  dst_sz 
)

Definition at line 588 of file util.c.

int b32_ntop ( const uint8_t *  src,
size_t  src_sz,
char *  dst,
size_t  dst_sz 
)

Definition at line 597 of file util.c.

int b32_ntop_extended_hex ( const uint8_t *  src,
size_t  src_sz,
char *  dst,
size_t  dst_sz 
)

Definition at line 603 of file util.c.

int ldns_b32_pton ( const char *  src,
size_t  src_sz,
uint8_t *  dst,
size_t  dst_sz 
)

Definition at line 745 of file util.c.

int ldns_b32_pton_extended_hex ( const char *  src,
size_t  src_sz,
uint8_t *  dst,
size_t  dst_sz 
)

Definition at line 751 of file util.c.

int b32_pton ( const char *  src,
size_t  src_sz,
uint8_t *  dst,
size_t  dst_sz 
)

Definition at line 760 of file util.c.

int b32_pton_extended_hex ( const char *  src,
size_t  src_sz,
uint8_t *  dst,
size_t  dst_sz 
)

Definition at line 766 of file util.c.