util.h File Reference

Go to the source code of this file.

## Data Structures

struct | ldns_schwartzian_compare_struct
| Structure to do a Schwartzian-like transformation, for instance when sorting. More...
struct | ldns_struct_lookup_table
| A general purpose lookup table. More...

## Macros

#define | dprintf(X, Y)
#define | LDNS_VERSION "1.9.2"
#define | LDNS_REVISION ((1<<16)|(9<<8)|(2))
#define | INLINE static inline
| splint static inline workaround
#define | LDNS_MALLOC(type)
| Memory management macros.
#define | LDNS_XMALLOC(type, count)
#define | LDNS_CALLOC(type, count)
#define | LDNS_REALLOC(ptr, type)
#define | LDNS_XREALLOC(ptr, type, count)
#define | LDNS_FREE(ptr)
#define | LDNS_DEP printf("DEPRECATED FUNCTION!\n");
#define | ldns_serial_arithmitics_gmtime_r ldns_serial_arithmetics_gmtime_r

## Typedefs

typedef struct ldns_struct_lookup_table | ldns_lookup_table

## Functions

ldns_lookup_table * | ldns_lookup_by_name (ldns_lookup_table table[], const char *name)
| Looks up the table entry by name, returns NULL if not found.
ldns_lookup_table * | ldns_lookup_by_id (ldns_lookup_table table[], int id)
| Looks up the table entry by id, returns NULL if not found.
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, signed char value)
| sets the specified bit in the specified byte to 1 if value is true, 0 if false The bits are counted from right to left, so bit #0 is the right most bit.
int | ldns_hexdigit_to_int (char ch)
| Returns the int value of the given (hex) digit.
char | ldns_int_to_hexdigit (int ch)
| 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_arithmetics_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 arithmetics (rfc1982).
int | ldns_init_random (FILE *fd, unsigned int size)
| Seed the random function.
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_data, size_t src_data_length, char *target_text_buffer, size_t target_text_buffer_size)
int | ldns_b32_ntop_extended_hex (const uint8_t *src_data, size_t src_data_length, char *target_text_buffer, size_t target_text_buffer_size)
int | b32_ntop (const uint8_t *src_data, size_t src_data_length, char *target_text_buffer, size_t target_text_buffer_size)
int | b32_ntop_extended_hex (const uint8_t *src_data, size_t src_data_length, char *target_text_buffer, size_t target_text_buffer_size)
int | ldns_b32_pton (const char *src_text, size_t src_text_length, uint8_t *target_data_buffer, size_t target_data_buffer_size)
int | ldns_b32_pton_extended_hex (const char *src_text, size_t src_text_length, uint8_t *target_data_buffer, size_t target_data_buffer_size)
int | b32_pton (const char *src_text, size_t src_text_length, uint8_t *target_data_buffer, size_t target_data_buffer_size)
int | b32_pton_extended_hex (const char *src_text, size_t src_text_length, uint8_t *target_data_buffer, size_t target_data_buffer_size)

## Macro Definition Documentation

## dprintf

#define dprintf | ( |  | X,
|  |  | Y )

Value:
fprintf(stderr, (X), (Y))

Definition at line 27 of file util.h.

## LDNS_VERSION

#define LDNS_VERSION "1.9.2"

Definition at line 30 of file util.h.

## LDNS_REVISION

#define LDNS_REVISION ((1<<16)|(9<<8)|(2))

Definition at line 31 of file util.h.

## INLINE

#define INLINE static inline

splint static inline workaround

Definition at line 42 of file util.h.

## LDNS_MALLOC

#define LDNS_MALLOC | ( |  | type | ) |

Value:
LDNS_XMALLOC(type, 1)
LDNS_XMALLOC
#define LDNS_XMALLOC(type, count)
Definition util.h:51

Memory management macros.

Definition at line 49 of file util.h.

## LDNS_XMALLOC

#define LDNS_XMALLOC | ( |  | type,
|  |  | count )

Value:
((type *) malloc((count) * sizeof(type)))

Definition at line 51 of file util.h.

## LDNS_CALLOC

#define LDNS_CALLOC | ( |  | type,
|  |  | count )

Value:
((type *) calloc((count), sizeof(type)))

Definition at line 53 of file util.h.

## LDNS_REALLOC

#define LDNS_REALLOC | ( |  | ptr,
|  |  | type )

Value:
LDNS_XREALLOC((ptr), type, 1)
LDNS_XREALLOC
#define LDNS_XREALLOC(ptr, type, count)
Definition util.h:57

Definition at line 55 of file util.h.

## LDNS_XREALLOC

#define LDNS_XREALLOC | ( |  | ptr,
|  |  | type,
|  |  | count )

Value:
((type *) realloc((ptr), (count) * sizeof(type)))

Definition at line 57 of file util.h.

## LDNS_FREE

#define LDNS_FREE | ( |  | ptr | ) |

Value:
do { free((ptr)); (ptr) = NULL; } while (0)

Definition at line 60 of file util.h.

## LDNS_DEP

#define LDNS_DEP printf("DEPRECATED FUNCTION!\n");

Definition at line 63 of file util.h.

## ldns_serial_arithmitics_gmtime_r

#define ldns_serial_arithmitics_gmtime_r ldns_serial_arithmetics_gmtime_r

Definition at line 314 of file util.h.

## Typedef Documentation

## ldns_lookup_table

typedef struct ldns_struct_lookup_table ldns_lookup_table

Definition at line 182 of file util.h.

## Function Documentation

## ldns_lookup_by_name()

ldns_lookup_table * ldns_lookup_by_name | ( | ldns_lookup_table | table[],
|  | const char * | name )

Looks up the table entry by name, returns NULL if not found.

Parameters

  [in] | table | the lookup table to search in
  [in] | name | what to search for

Returns
  the item found

## ldns_lookup_by_id()

ldns_lookup_table * ldns_lookup_by_id | ( | ldns_lookup_table | table[],
|  | int | id )

Looks up the table entry by id, returns NULL if not found.

Parameters

  [in] | table | the lookup table to search in
  [in] | id | what to search for

Returns
  the item found

References INLINE.

## ldns_get_bit()

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] | bits | array holding the bits
  [in] | index | to the wanted bit

Returns

Definition at line 52 of file util.c.

## ldns_get_bit_r()

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] | bits | array holding the bits
  [in] | index | to the wanted bit

Returns
  1 or 0 depending no the bit state

Definition at line 62 of file util.c.

## ldns_set_bit()

void ldns_set_bit | ( | uint8_t * | byte,
|  | int | bit_nr,
|  | signed char | value )

sets the specified bit in the specified byte to 1 if value is true, 0 if false The bits are counted from right to left, so bit #0 is the right most bit.

Parameters

  [in] | byte | the bit to set the bit in
  [in] | bit_nr | the bit to set (0 <= n <= 7)
  [in] | value | whether to set the bit to 1 or 0

Returns
  1 or 0 depending no the bit state

Definition at line 72 of file util.c.

## ldns_hexdigit_to_int()

int ldns_hexdigit_to_int | ( | char | ch | ) |

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

Parameters

  [in] | ch | the hex char to convert

Returns
  the converted decimal value

Definition at line 88 of file util.c.

## ldns_int_to_hexdigit()

char ldns_int_to_hexdigit | ( | int | ch | ) |

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

Parameters

  [in] | ch | the int to convert

Returns
  the converted hex char

Definition at line 113 of file util.c.

## ldns_hexstring_to_data()

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

Converts a hex string to binary data.

Parameters

  [out] | data | The binary result is placed here. At least strlen(str)/2 bytes should be allocated
  [in] | str | The 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().

## ldns_version()

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.

## ldns_mktime_from_utc()

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] | tm | a struct tm* with the date

Returns
  the seconds since epoch

Definition at line 194 of file util.c.

## mktime_from_utc()

time_t mktime_from_utc | ( | const struct tm * | tm | ) |

Definition at line 219 of file util.c.

References ldns_mktime_from_utc().

## ldns_serial_arithmetics_gmtime_r()

struct tm * ldns_serial_arithmetics_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 arithmetics (rfc1982).

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

Parameters

  [in] | time | number of seconds since epoch (midnight, January 1st, 1970) to be interpreted as a serial arithmetics number relative to now.
  [in] | now | number of seconds since epoch (midnight, January 1st, 1970) to which the time value is compared to determine the final value.
  [out] | result | the struct with the broken-out time information

Returns
  result on success or NULL on error

Definition at line 304 of file util.c.

## ldns_init_random()

int ldns_init_random | ( | FILE * | fd,
|  | unsigned int | size )

Seed the random function.

If the file descriptor is specified, the random generator is seeded with data from that file. If not, /dev/urandom is used.

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.

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

Parameters

  [in] | fd | a file providing entropy data for the seed
  [in] | size | the number of bytes to use as entropy data. If this is 0, only the minimal amount is taken (usually 4 bytes)

Returns
  0 if seeding succeeds, 1 if it fails

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 339 of file util.c.

References LDNS_FREE, and LDNS_XMALLOC.

## ldns_get_random()

uint16_t ldns_get_random | ( | void |  | ) |

Get random number.

Returns
  random number.

Definition at line 417 of file util.c.

## ldns_bubblebabble()

char * ldns_bubblebabble | ( | uint8_t * | data,
|  | size_t | len )

Encode data as BubbleBabble.

Parameters

  [in] | data | a pointer to data to be encoded
  [in] | len | size the number of bytes of data

Returns
  a string of BubbleBabble

Definition at line 435 of file util.c.

References LDNS_XMALLOC.

## ldns_b32_ntop()

int ldns_b32_ntop | ( | const uint8_t * | src_data,
|  | size_t | src_data_length,
|  | char * | target_text_buffer,
|  | size_t | target_text_buffer_size )

Definition at line 605 of file util.c.

## ldns_b32_ntop_extended_hex()

int ldns_b32_ntop_extended_hex | ( | const uint8_t * | src_data,
|  | size_t | src_data_length,
|  | char * | target_text_buffer,
|  | size_t | target_text_buffer_size )

Definition at line 611 of file util.c.

## b32_ntop()

int b32_ntop | ( | const uint8_t * | src_data,
|  | size_t | src_data_length,
|  | char * | target_text_buffer,
|  | size_t | target_text_buffer_size )

Definition at line 620 of file util.c.

## b32_ntop_extended_hex()

int b32_ntop_extended_hex | ( | const uint8_t * | src_data,
|  | size_t | src_data_length,
|  | char * | target_text_buffer,
|  | size_t | target_text_buffer_size )

Definition at line 626 of file util.c.

## ldns_b32_pton()

int ldns_b32_pton | ( | const char * | src_text,
|  | size_t | src_text_length,
|  | uint8_t * | target_data_buffer,
|  | size_t | target_data_buffer_size )

Definition at line 771 of file util.c.

## ldns_b32_pton_extended_hex()

int ldns_b32_pton_extended_hex | ( | const char * | src_text,
|  | size_t | src_text_length,
|  | uint8_t * | target_data_buffer,
|  | size_t | target_data_buffer_size )

Definition at line 777 of file util.c.

## b32_pton()

int b32_pton | ( | const char * | src_text,
|  | size_t | src_text_length,
|  | uint8_t * | target_data_buffer,
|  | size_t | target_data_buffer_size )

Definition at line 786 of file util.c.

## b32_pton_extended_hex()

int b32_pton_extended_hex | ( | const char * | src_text,
|  | size_t | src_text_length,
|  | uint8_t * | target_data_buffer,
|  | size_t | target_data_buffer_size )

Definition at line 792 of file util.c.