17 #include <sys/types.h>
27 #define dprintf(X,Y) fprintf(stderr, (X), (Y))
30 #define LDNS_VERSION "1.6.16"
31 #define LDNS_REVISION ((1<<16)|(6<<8)|(16))
40 # define INLINE static
42 # define INLINE static inline
49 #define LDNS_MALLOC(type) LDNS_XMALLOC(type, 1)
51 #define LDNS_XMALLOC(type, count) ((type *) malloc((count) * sizeof(type)))
53 #define LDNS_CALLOC(type, count) ((type *) calloc((count), sizeof(type)))
55 #define LDNS_REALLOC(ptr, type) LDNS_XREALLOC((ptr), type, 1)
57 #define LDNS_XREALLOC(ptr, type, count) \
58 ((type *) realloc((ptr), (count) * sizeof(type)))
60 #define LDNS_FREE(ptr) \
61 do { free((ptr)); (ptr) = NULL; } while (0)
63 #define LDNS_DEP printf("DEPRECATED FUNCTION!\n");
70 ldns_read_uint16(
const void *src)
72 #ifdef ALLOW_UNALIGNED_ACCESSES
73 return ntohs(*(uint16_t *) src);
75 uint8_t *
p = (uint8_t *) src;
76 return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
81 ldns_read_uint32(
const void *src)
83 #ifdef ALLOW_UNALIGNED_ACCESSES
84 return ntohl(*(uint32_t *) src);
86 uint8_t *
p = (uint8_t *) src;
87 return ( ((uint32_t) p[0] << 24)
88 | ((uint32_t) p[1] << 16)
89 | ((uint32_t) p[2] << 8)
99 ldns_write_uint16(
void *dst, uint16_t data)
101 #ifdef ALLOW_UNALIGNED_ACCESSES
102 * (uint16_t *) dst = htons(data);
104 uint8_t *p = (uint8_t *) dst;
105 p[0] = (uint8_t) ((data >> 8) & 0xff);
106 p[1] = (uint8_t) (data & 0xff);
111 ldns_write_uint32(
void *dst, uint32_t data)
113 #ifdef ALLOW_UNALIGNED_ACCESSES
114 * (uint32_t *) dst = htonl(data);
116 uint8_t *p = (uint8_t *) dst;
117 p[0] = (uint8_t) ((data >> 24) & 0xff);
118 p[1] = (uint8_t) ((data >> 16) & 0xff);
119 p[2] = (uint8_t) ((data >> 8) & 0xff);
120 p[3] = (uint8_t) (data & 0xff);
126 ldns_write_uint64_as_uint48(
void *dst, uint64_t data)
128 uint8_t *p = (uint8_t *) dst;
129 p[0] = (uint8_t) ((data >> 40) & 0xff);
130 p[1] = (uint8_t) ((data >> 32) & 0xff);
131 p[2] = (uint8_t) ((data >> 24) & 0xff);
132 p[3] = (uint8_t) ((data >> 16) & 0xff);
133 p[4] = (uint8_t) ((data >> 8) & 0xff);
134 p[5] = (uint8_t) (data & 0xff);
210 void ldns_set_bit(uint8_t *byte,
int bit_nr,
bool value);
218 ldns_power(
long a,
long b) {
330 char *target,
size_t targsize);
331 int b32_ntop(uint8_t
const *src,
size_t srclength,
332 char *target,
size_t targsize);
334 char *target,
size_t targsize);
336 char *target,
size_t targsize);
341 INLINE size_t ldns_b32_ntop_calculate_size(
size_t srcsize)
343 size_t result = ((((srcsize / 5) * 8) - 2) + 2);
348 int ldns_b32_pton(
char const *src,
size_t hashed_owner_str_len, uint8_t *target,
size_t targsize);
349 int b32_pton(
char const *src,
size_t hashed_owner_str_len, uint8_t *target,
size_t targsize);
351 int b32_pton_extended_hex(
char const *src,
size_t hashed_owner_str_len, uint8_t *target,
size_t targsize);
356 INLINE size_t ldns_b32_pton_calculate_size(
size_t srcsize)
358 size_t result = ((((srcsize) / 8) * 5));
363 INLINE time_t ldns_time(time_t *t) {
return time(t); }
int ldns_b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize)
time_t mktime_from_utc(const struct tm *tm)
void ldns_set_bit(uint8_t *byte, int bit_nr, bool value)
char * ldns_bubblebabble(uint8_t *data, size_t len)
Encode data as BubbleBabble.
char ldns_int_to_hexdigit(int i)
Returns the char (hex) representation of the given int.
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 righ...
time_t ldns_mktime_from_utc(const struct tm *tm)
Convert TM to seconds since epoch (midnight, January 1st, 1970).
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 ar...
int b32_ntop_extended_hex(uint8_t const *src, size_t srclength, char *target, size_t targsize)
#define INLINE
splint static inline workaround
uint16_t ldns_get_random(void)
Get random number.
const char * ldns_version(void)
Show the internal library version.
int b32_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize)
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...
Structure to do a Schwartzian-like transformation, for instance when sorting.
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
int ldns_b32_ntop_extended_hex(uint8_t const *src, size_t srclength, char *target, size_t targsize)
A general purpose lookup table.
int ldns_b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize)
int ldns_hexstring_to_data(uint8_t *data, const char *str)
Converts a hex string to binary data.
int b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize)
int ldns_hexdigit_to_int(char ch)
Returns the int value of the given (hex) digit.
ldns_lookup_table * ldns_lookup_by_name(ldns_lookup_table *table, const char *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...
Common definitions for LDNS.
void * transformed_object
int b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize)
int ldns_b32_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize)