|
sdns
low-level DNS library
|
#include <stdint.h>

Go to the source code of this file.
Classes | |
| struct | sdns_question |
| struct | _sdns_opt_rdata |
| struct | sdns_opt_ttl |
| struct | _sdns_rr |
| struct | sdns_header |
| struct | sdns_message |
| struct | sdns_rr_A |
| struct | sdns_rr_AAAA |
| struct | txt_data |
| struct | _sdns_rr_TXT |
| struct | sdns_rr_SOA |
| struct | sdns_rr_MX |
| struct | sdns_rr_NS |
| struct | sdns_rr_PTR |
| struct | sdns_rr_CNAME |
| struct | sdns_rr_OPT_EDE |
| struct | sdns_rr_RRSIG |
| struct | sdns_rr_SRV |
| struct | sdns_rr_URI |
| struct | sdns_rr_NID |
| struct | sdns_rr_HINFO |
| struct | sdns_rr_L32 |
| struct | sdns_rr_L64 |
| struct | sdns_rr_LP |
| struct | sdns_rr_CAA |
| struct | sdns_context |
Macros | |
| #define | TO_OUTPUT(A, B) do{if (NULL == A) {fprintf(stdout, B);}else{strcpy(A,B);}}while(0); |
| #define | UDP_PAYLOAD_SIZE 1232 |
| Default UDP payload size for EDNS0. | |
| #define | DNS_HEADER_LENGTH 12 |
| Standard DNS Header length. | |
| #define | SDNS_ERROR_MEMORY_ALLOC_FAILED -1 |
| memory allocation using malloc() failed | |
| #define | SDNS_ERROR_BUFFER_TOO_SHORT -2 |
| DNS packet length is shorter than expected. | |
| #define | SDNS_ERROR_QNAME_IS_NULL -3 |
| Qname of the question section can not be null. | |
| #define | SDNS_ERROR_HOSTNAME_TOO_LONG -4 |
| Hostname can not be more than 255 characters. | |
| #define | SDNS_ERROR_WRONG_LABEL_SPECIFIED -5 |
| Label name is too long or malformed. | |
| #define | SDNS_ERROR_BUFFER_IS_NULL -6 |
| passed buffer to the function is NULL | |
| #define | SDNS_ERROR_BUFFER_IS_SMALL -7 |
| buffer is shorter than expected | |
| #define | SDNS_ERROR_INVALID_DNS_PACKET -8 |
| The packet is not a valid DNS packet. | |
| #define | SDNS_ERROR_MORE_THAN_ONE_QUESTION_FOUND -9 |
| Each DNS packet must have exactly one question section. | |
| #define | SDNS_ERROR_RR_NULL -10 |
| Resource Record section pointer is NULL. | |
| #define | SDNS_ERROR_ELSIMPLE -11 |
| Success code for simple encoding of the name. | |
| #define | SDNS_ERROR_ELCOMPRESSED -12 |
| Success code for compressed encoding of the name. | |
| #define | SDNS_ERROR_LABEL_MAX_63 -13 |
| each part of the name must be <= 63 characters | |
| #define | SDNS_ERROR_ILLEGAL_COMPRESSION -14 |
| Compressed label found when it's illegal. | |
| #define | SDNS_ERROR_RR_SECTION_MALFORMED -15 |
| Resource Record section is malformed (not enough or wrong data) | |
| #define | SDNS_ERROR_INVALID_HEX_VALUE -16 |
| User entered a hex string that is not valid. | |
| #define | SDNS_ERROR_WRONG_INPUT_PARAMETER -17 |
| The input parameter is not valid. | |
| #define | SDNS_ERROR_NSID_NOT_FOUND -18 |
| There is no NSID in the DNS packet. | |
| #define | SDNS_ERROR_CLIENT_COOKIE_NOT_FOUND -19 |
| There is no client cookie in the DNS packet. | |
| #define | SDNS_ERROR_CHARACTER_STRING_TOO_LONG -20 |
| Maximum size of character string is 255 character. | |
| #define | SDNS_ERROR_NO_ANSWER_FOUND -21 |
| This error shows that the DNS context has no answer section. | |
| #define | SDNS_ERROR_CAN_NOT_READ_SECTION -22 |
| For any reason, it's not possible to decode or copy the rdata of the section. | |
| #define | SDNS_ERROR_INVALID_IPv6_FOUND -23 |
| The code only accepts IPv6 in a format of ":" separated hex values. | |
| #define | SDNS_ERROR_NO_AUTHORITY_FOUND -24 |
| This error shows that the DNS context has no authority section. | |
| #define | SDNS_ERROR_NO_ADDITIONAL_FOUND -25 |
| This error shows that the DNS context has no additional section. | |
| #define | SDNS_ERROR_ADDITIONAL_RR_OPT -26 |
| Additional section is of type OPT. Use the relevant function to fetch it. | |
| #define | DNS_SECTION_ANSWER 1 |
| Macro defining the answer section. | |
| #define | DNS_SECTION_AUTHORITY 2 |
| Macro defining the authority section. | |
| #define | DNS_SECTION_ADDITIONAL 3 |
| Macro defining the additional section. | |
| #define | DNS_SECTION_QUESTION 4 |
| Macro defining the question section. | |
| #define | SDNS_QR_MASK 0x8000 |
| #define | SDNS_OPCODE_MASK 0x7800 |
| #define | SDNS_AA_MASK 0x0400 |
| #define | SDNS_TC_MASK 0x0200 |
| #define | SDNS_RD_MASK 0x0100 |
| #define | SDNS_RA_MASK 0x0080 |
| #define | SDNS_Z_MASK 0x0040 |
| #define | SDNS_AD_MASK 0x0020 |
| #define | SDNS_CD_MASK 0x0010 |
| #define | SDNS_RCODE_MASK 0x000F |
Typedefs | |
| typedef struct _sdns_opt_rdata | sdns_opt_rdata |
| see _sdns_opt_rdata for more info | |
| typedef struct _sdns_rr | sdns_rr |
| See _sdns_rr for more info. | |
| typedef struct _sdns_rr_TXT | sdns_rr_TXT |
Functions | |
| int | sdns_make_query (sdns_context *ctx, sdns_rr_type qtype, sdns_q_class cls, char *qname, int enable_edns0) |
| Creates a DNS question query. | |
| int | sdns_to_wire (sdns_context *ctx) |
| Coverts a DNS context to binary format. | |
| int | sdns_from_wire (sdns_context *ctx) |
| Converts the raw data received from socket (bytes) to a DNS packet. | |
| void | sdns_error_string (int err, char **err_buff) |
| Coverts error codes to a string. | |
| sdns_context * | sdns_init_context (void) |
| Initialize and create a new DNS context. | |
| void | sdns_free_context (sdns_context *ctx) |
| Frees the context allocated by sdns_init_context(). | |
| int | sdns_add_answer_section (sdns_context *ctx, sdns_rr *rr) |
| Creates an answer section for the DNS packet. | |
| int | sdns_add_authority_section (sdns_context *ctx, sdns_rr *rr) |
| Adds a new RR to the authority section of the DNS packet. | |
| int | sdns_add_additional_section (sdns_context *ctx, sdns_rr *rr) |
| Adds a new RR to the additional section of the DNS packet. | |
| int | check_if_qtype_is_valid (uint16_t qtype) |
| This function checks if the given qtype code is valid or not. | |
| int | check_if_rrtype_is_valid (uint16_t qtype) |
| This function checks if the given RR type is valid or not. | |
| int | check_if_qclass_is_valid (uint16_t qclass) |
| This function checks if the given Question class is valid or not. | |
| int | check_if_rrclass_is_valid (uint16_t qclass) |
| This function checks if the given RR class is valid or not. | |
| sdns_message * | sdns_init_message (void) |
| Initialize a DNS message structure (sdns_message). | |
| sdns_rr * | sdns_init_rr (char *name, uint16_t type, uint16_t class, uint32_t ttl, uint16_t rdlength, uint8_t decoded, void *rdata) |
| Initialize an RR data structure. | |
| int | sdns_create_edns_option (uint16_t, uint16_t, char *, sdns_opt_rdata **) |
| int | sdns_add_edns (sdns_context *ctx, sdns_opt_rdata *opt) |
| sdns_opt_rdata * | sdns_create_edns0_ede (uint16_t info_code, char *extra_text, uint16_t extra_text_len) |
| Creates EDNS0 extended DNS error option. | |
| sdns_opt_rdata * | sdns_create_edns0_nsid (char *nsid, uint16_t nsid_len) |
| int | sdns_ends0_option_code_to_text (sdns_edns0_option_code oc, char *buffer) |
| Copies the text description of the EDNS0 option code to the buffer. | |
| void * | sdns_copy_rr_section (sdns_context *, sdns_rr *) |
| void * | sdns_decode_rr_section (sdns_context *, sdns_rr *) |
| sdns_rr_A * | sdns_decode_rr_A (sdns_context *, sdns_rr *) |
| sdns_rr_AAAA * | sdns_decode_rr_AAAA (sdns_context *, sdns_rr *) |
| sdns_rr_TXT * | sdns_decode_rr_TXT (sdns_context *, sdns_rr *) |
| sdns_rr_SOA * | sdns_decode_rr_SOA (sdns_context *, sdns_rr *) |
| sdns_rr_MX * | sdns_decode_rr_MX (sdns_context *, sdns_rr *) |
| sdns_rr_NS * | sdns_decode_rr_NS (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_PTR * | sdns_decode_rr_PTR (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_CNAME * | sdns_decode_rr_CNAME (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_RRSIG * | sdns_decode_rr_RRSIG (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_SRV * | sdns_decode_rr_SRV (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_HINFO * | sdns_decode_rr_HINFO (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_URI * | sdns_decode_rr_URI (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_NID * | sdns_decode_rr_NID (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_L32 * | sdns_decode_rr_L32 (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_L64 * | sdns_decode_rr_L64 (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_LP * | sdns_decode_rr_LP (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_CAA * | sdns_decode_rr_CAA (sdns_context *ctx, sdns_rr *rr) |
| sdns_opt_rdata * | sdns_decode_rr_OPT (sdns_context *ctx, sdns_rr *rr) |
| sdns_rr_A * | sdns_init_rr_A (uint32_t ipaddress) |
| Initialize a structure of sdns_rr_A. | |
| sdns_rr_AAAA * | sdns_init_rr_AAAA (char *aaaa) |
| Initialize a structure of sdns_rr_AAAA. | |
| sdns_rr_TXT * | sdns_init_rr_TXT (char *data, uint16_t data_len) |
| Initialize a structure of sdns_rr_TXT. | |
| sdns_rr_SRV * | sdns_init_rr_SRV (uint16_t Priority, uint16_t Weight, uint16_t Port, char *target) |
| Initialize a structure of sdns_rr_SRV. | |
| sdns_rr_MX * | sdns_init_rr_MX (uint16_t preference, char *exchange) |
| Initialize a structure of sdns_rr_MX. | |
| sdns_rr_NS * | sdns_init_rr_NS (char *nsdname) |
| Initialize a structure of sdns_rr_NS. | |
| sdns_rr_PTR * | sdns_init_rr_PTR (char *ptrdname) |
| Initialize a structure of sdns_rr_PTR. | |
| sdns_rr_CNAME * | sdns_init_rr_CNAME (char *cname) |
| Initialize a structure of sdns_rr_CNAME. | |
| sdns_rr_NID * | sdns_init_rr_NID (uint16_t preference, char *nodid) |
| Initialize a structure of sdns_rr_NID. | |
| sdns_rr_L32 * | sdns_init_rr_L32 (uint16_t preference, uint32_t locator32) |
| Initialize a structure of sdns_rr_L32. | |
| sdns_rr_L64 * | sdns_init_rr_L64 (uint16_t preference, char *locator64) |
| Initialize a structure of sdns_rr_L64. | |
| sdns_rr_LP * | sdns_init_rr_LP (uint16_t preference, char *fqdn) |
| Initialize a structure of sdns_rr_LP. | |
| sdns_rr_CAA * | sdns_init_rr_CAA (uint8_t flag, char *tag, uint8_t tag_len, char *value, uint16_t value_len) |
| Initialize a structure of sdns_rr_CAA. | |
| void | sdns_free_opt_rdata (sdns_opt_rdata *opt) |
| sdns_opt_rdata * | sdns_init_opt_rdata (void) |
| sdns_rr_SRV * | sdns_init_SRV (uint16_t, uint16_t, uint16_t, char *) |
| sdns_rr_URI * | sdns_init_rr_URI (uint16_t, uint16_t, char *, uint16_t) |
| sdns_rr_RRSIG * | sdns_init_rr_RRSIG (uint16_t, uint8_t, uint8_t, uint32_t, uint32_t, uint32_t, uint8_t, char *, char *, uint16_t) |
| sdns_rr_HINFO * | sdns_init_rr_HINFO (uint8_t cpu_len, char *cpu, uint8_t os_len, char *os) |
| sdns_rr_SOA * | sdns_init_rr_SOA (char *mname, char *rname, uint32_t expire, uint32_t minimum, uint32_t refresh, uint32_t retry, uint32_t serial) |
| void | sdns_free_rr_A (sdns_rr_A *a) |
| Free the memory of the structure of type sdns_rr_A. | |
| void | sdns_free_rr_MX (sdns_rr_MX *mx) |
| Free the memory of the structure of type sdns_rr_MX. | |
| void | sdns_free_rr_TXT (sdns_rr_TXT *txt) |
| Free the memory of the structure of type sdns_rr_TXT. | |
| void | sdns_free_rr_AAAA (sdns_rr_AAAA *aaaa) |
| Free the memory of the structure of type sdns_rr_AAAA. | |
| void | sdns_free_rr_SOA (sdns_rr_SOA *soa) |
| Free the memory of the structure of type sdns_rr_SOA. | |
| void | sdns_free_rr_NS (sdns_rr_NS *ns) |
| Free the memory of the structure of type sdns_rr_NS. | |
| void | sdns_free_rr_PTR (sdns_rr_PTR *ptr) |
| Free the memory of the structure of type sdns_rr_PTR. | |
| void | sdns_free_rr_CNAME (sdns_rr_CNAME *cname) |
| Free the memory of the structure of type sdns_rr_CNAME. | |
| void | sdns_free_rr_RRSIG (sdns_rr_RRSIG *rrsig) |
| Free the memory of the structure of type sdns_rr_RRSIG. | |
| void | sdns_free_rr_SRV (sdns_rr_SRV *srv) |
| Free the memory of the structure of type sdns_rr_SRV. | |
| void | sdns_free_rr_HINFO (sdns_rr_HINFO *hinfo) |
| Free the memory of the structure of type sdns_rr_HINFO. | |
| void | sdns_free_rr_URI (sdns_rr_URI *uri) |
| Free the memory of the structure of type sdns_rr_URI. | |
| void | sdns_free_rr_NID (sdns_rr_NID *nid) |
| Free the memory of the structure of type sdns_rr_NID. | |
| void | sdns_free_rr_L32 (sdns_rr_L32 *l32) |
| Free the memory of the structure of type sdns_rr_L32. | |
| void | sdns_free_rr_L64 (sdns_rr_L64 *l64) |
| Free the memory of the structure of type sdns_rr_L64. | |
| void | sdns_free_rr_LP (sdns_rr_LP *lp) |
| Free the memory of the structure of type sdns_rr_LP. | |
| void | sdns_free_rr_CAA (sdns_rr_CAA *caa) |
| Free the memory of the structure of type sdns_rr_CAA. | |
| sdns_opt_rdata * | sdns_create_edns0_cookie (char *client_cookie, char *server_cookie, uint8_t server_cookie_len) |
| Creates and adds a cookie in the DNS packet. | |
| void | sdns_rr_type_to_string (uint16_t t, char *buff) |
| Gets the string representation of the TYPE tp in to buffer | |
| void | sdns_class_to_string (uint16_t cls, char *buff) |
| Gets the string representation of the CLASS cls in to buffer | |
| int | sdns_convert_type_to_int (char *type) |
| Converts text type to its numerical value. | |
| int | sdns_convert_class_to_int (char *cls) |
| Converts text class to its numerical value. | |
| void | sdns_free_section (sdns_rr *rr) |
| free a DNS resource record no matter of the type | |
| #define SDNS_ERROR_ILLEGAL_COMPRESSION -14 |
Compressed label found when it's illegal.
In some cases like RRSIG, the name can not be compressed (e.g., signer's name in RRSIG). So if we found a compressed name in those sections, we return this error
| typedef struct _sdns_opt_rdata sdns_opt_rdata |
see _sdns_opt_rdata for more info
See _sdns_opt_rdata structure for detail.
| typedef struct _sdns_rr_TXT sdns_rr_TXT |
check the definition of _sdns_rr_TXT.
| enum sdns_ede_code |
List of known value for Extended DNS Errors (EDE). The full list is available in RFC 8914
Possible valid values for the option code of EDNS0 https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11
| enum sdns_opcode |
The list of opcodes can be found at: http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5
| Enumerator | |
|---|---|
| sdns_opcode_Query | RFC1035. |
| sdns_opcode_IQuery | RFC1035. |
| sdns_opcode_Status | RFC1035. |
| sdns_opcode_Notify | RFC1996. |
| sdns_opcode_Update | RFC2136. |
| sdns_opcode_DSO | RFC8490. |
| enum sdns_q_class |
| enum sdns_rcode |
The list of standard error codes for DNS can be found at: http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
| enum sdns_rr_class |
| enum sdns_rr_type |
Here is the list of possible RR types reitrieved from: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4
| int check_if_qclass_is_valid | ( | uint16_t | qclass | ) |
This function checks if the given Question class is valid or not.
| qclass | input Resource record class |
| int check_if_qtype_is_valid | ( | uint16_t | qtype | ) |
This function checks if the given qtype code is valid or not.
| qtype | 16-bit unsigned integer |
| int check_if_rrclass_is_valid | ( | uint16_t | qclass | ) |
This function checks if the given RR class is valid or not.
| qclass | input Resource record class |
| int check_if_rrtype_is_valid | ( | uint16_t | qtype | ) |
This function checks if the given RR type is valid or not.
| qtype | input Resource record type |
| int sdns_add_additional_section | ( | sdns_context * | ctx, |
| sdns_rr * | rr | ||
| ) |
Adds a new RR to the additional section of the DNS packet.
| ctx | A pointer to DNS context created by sdns_init_context() |
| rr | A pointer to the RR we want to add. |
This function is exactly the same as sdns_add_answer_section() but adds the new record to additional section of the DNS packet instead of the answer section.
For more info, check the provided example in sdns_add_answer_section() function.
NOTE: We don't use this function to add EDNS0 options. Instead, we use sdns_add_edns() function.
| int sdns_add_answer_section | ( | sdns_context * | ctx, |
| sdns_rr * | rr | ||
| ) |
Creates an answer section for the DNS packet.
| ctx | A pointer to the DNS context created by sdns_init_context(). |
| rr | A pointer to the sdns_rr structure we want to add. |
| int sdns_add_authority_section | ( | sdns_context * | ctx, |
| sdns_rr * | rr | ||
| ) |
Adds a new RR to the authority section of the DNS packet.
| ctx | A pointer to DNS context created by sdns_init_context() |
| rr | A pointer to the RR we want to add. |
This function is exactly the same as sdns_add_answer_section() but adds the new record to authority section of the DNS packet instead of the answer section.
For more info, check the provided example in sdns_add_answer_section() function.
| void sdns_class_to_string | ( | uint16_t | cls, |
| char * | buff | ||
| ) |
Gets the string representation of the CLASS cls in to buffer
| cls | A 16bit integer, one of the possible values of sdns_rr_class or sdns_q_class |
| buff | A pointer to the user-provided buffer |
The buff must be long enough to cover all classes.
Currently, a buffer of length 20 is enough.
| int sdns_convert_class_to_int | ( | char * | cls | ) |
Converts text class to its numerical value.
| cls | a pointer to the class string (e.g., "IN" or "ch") |
| int sdns_convert_type_to_int | ( | char * | type | ) |
Converts text type to its numerical value.
| type | a pointer to the type string (e.g., "AAAA") |
| sdns_opt_rdata * sdns_create_edns0_cookie | ( | char * | client_cookie, |
| char * | server_cookie, | ||
| uint8_t | server_cookie_len | ||
| ) |
Creates and adds a cookie in the DNS packet.
| client_cookie | This parameter can not be NULL. It must be provided and the length is exactly 8 bytes. |
| server_cookie | this is an optional parameter which can be NULL or a pointer to a memory which stores the cookie |
| server_cookie_len | The length of the server cookie which can be between 8 and 32 (both valued included). |
the caller can free() the memory of 'client_cookie' and 'server_cookie' params after calling the method. The library creates an internal copy of the data.
On success, you can add the returned structure to the DNS packet by calling sdns_create_edns_option() function.
| sdns_opt_rdata * sdns_create_edns0_ede | ( | uint16_t | info_code, |
| char * | extra_text, | ||
| uint16_t | extra_text_len | ||
| ) |
Creates EDNS0 extended DNS error option.
| info_code | One of the possible values of sdns_ede_code |
| extra_text | A text description of the error or whatever you want to send |
| extra_text_len | the length of the extra_text filed (as it's not necessarily nul-terminated) |
This function creates a new copy of 'extra_text' field. So the caller is responsible to free the memory of 'extra_text' if it's a heap-allocated memory.
| int sdns_ends0_option_code_to_text | ( | sdns_edns0_option_code | oc, |
| char * | buffer | ||
| ) |
Copies the text description of the EDNS0 option code to the buffer.
| oc | the numerical value of the edns0 option code, one of the possible values of sdns_edns0_option_code |
| buffer | The user provided buffer to receive the string. |
The user provided buffer must be large enough to cover the longest string. You can pass a buffer of length 100 to make sure it goes well.
if the return value is 0, it means the given 'oc' value is a valid EDNS option code. If the return value is 1, it means the given 'oc' value is not a valid EDNS option code.
This means you can also use this function as a validator to check of 'oc' is valid or not.
| void sdns_error_string | ( | int | err, |
| char ** | err_buff | ||
| ) |
Coverts error codes to a string.
| err | the error code you received from one of the functions or any DNS defined error. |
| err_buff | A double pointer to the buffer to receive the string. if it's NULL, we will allocate memory. |
The err_buff parameter must be large enough to cover all possible error codes. Currently, no error string is larger than 256. Hence, 256 bytes of buffer is large enough and safe.
check the source code example in sdns_make_query() for more information.
| void sdns_free_context | ( | sdns_context * | ctx | ) |
Frees the context allocated by sdns_init_context().
| ctx | A pointer to the context. |
To prevent memory leak, you must free the context all the time.
This function will call all other sdns_free_*() functions recursively to free the whole memory.
| void sdns_free_rr_A | ( | sdns_rr_A * | a | ) |
Free the memory of the structure of type sdns_rr_A.
| a | A pointer to the structure |
| void sdns_free_rr_AAAA | ( | sdns_rr_AAAA * | aaaa | ) |
Free the memory of the structure of type sdns_rr_AAAA.
| aaaa | A pointer to the structure |
| void sdns_free_rr_CAA | ( | sdns_rr_CAA * | caa | ) |
Free the memory of the structure of type sdns_rr_CAA.
| caa | A pointer to the structure |
| void sdns_free_rr_CNAME | ( | sdns_rr_CNAME * | cname | ) |
Free the memory of the structure of type sdns_rr_CNAME.
| cname | A pointer to the structure |
| void sdns_free_rr_HINFO | ( | sdns_rr_HINFO * | hinfo | ) |
Free the memory of the structure of type sdns_rr_HINFO.
| hinfo | A pointer to the structure |
| void sdns_free_rr_L32 | ( | sdns_rr_L32 * | l32 | ) |
Free the memory of the structure of type sdns_rr_L32.
| l32 | A pointer to the structure |
| void sdns_free_rr_L64 | ( | sdns_rr_L64 * | l64 | ) |
Free the memory of the structure of type sdns_rr_L64.
| l64 | A pointer to the structure |
| void sdns_free_rr_LP | ( | sdns_rr_LP * | lp | ) |
Free the memory of the structure of type sdns_rr_LP.
| lp | A pointer to the structure |
| void sdns_free_rr_MX | ( | sdns_rr_MX * | mx | ) |
Free the memory of the structure of type sdns_rr_MX.
| mx | A pointer to the structure |
| void sdns_free_rr_NID | ( | sdns_rr_NID * | nid | ) |
Free the memory of the structure of type sdns_rr_NID.
| nid | A pointer to the structure |
| void sdns_free_rr_NS | ( | sdns_rr_NS * | ns | ) |
Free the memory of the structure of type sdns_rr_NS.
| ns | A pointer to the structure |
| void sdns_free_rr_PTR | ( | sdns_rr_PTR * | ptr | ) |
Free the memory of the structure of type sdns_rr_PTR.
| ptr | A pointer to the structure |
| void sdns_free_rr_RRSIG | ( | sdns_rr_RRSIG * | rrsig | ) |
Free the memory of the structure of type sdns_rr_RRSIG.
| rrsig | A pointer to the structure |
| void sdns_free_rr_SOA | ( | sdns_rr_SOA * | soa | ) |
Free the memory of the structure of type sdns_rr_SOA.
| soa | A pointer to the structure |
| void sdns_free_rr_SRV | ( | sdns_rr_SRV * | srv | ) |
Free the memory of the structure of type sdns_rr_SRV.
| srv | A pointer to the structure |
| void sdns_free_rr_TXT | ( | sdns_rr_TXT * | txt | ) |
Free the memory of the structure of type sdns_rr_TXT.
| txt | A pointer to the structure |
| void sdns_free_rr_URI | ( | sdns_rr_URI * | uri | ) |
Free the memory of the structure of type sdns_rr_URI.
| uri | A pointer to the structure |
| void sdns_free_section | ( | sdns_rr * | rr | ) |
free a DNS resource record no matter of the type
| rr | a pointer to the memory of sdns_rr which holds the resource record section to be freed |
| int sdns_from_wire | ( | sdns_context * | ctx | ) |
Converts the raw data received from socket (bytes) to a DNS packet.
| ctx | A pointer to DNS context created by sdns_init_context(). |
A description of all error codes returned by this method can be retrieved by calling sdns_error_string() function.
| sdns_context * sdns_init_context | ( | void | ) |
Initialize and create a new DNS context.
This function is responsible for creating a new context for DNS.
For each DNS packet, you must create a new context. This function does nothing more than creating a structure and allocating the necessary memories.
| sdns_message * sdns_init_message | ( | void | ) |
Initialize a DNS message structure (sdns_message).
Users don't need to this method directly. We use this method internally when we call sdns_init_context().
| sdns_rr * sdns_init_rr | ( | char * | name, |
| uint16_t | type, | ||
| uint16_t | class, | ||
| uint32_t | ttl, | ||
| uint16_t | rdlength, | ||
| uint8_t | decoded, | ||
| void * | rdata | ||
| ) |
Initialize an RR data structure.
| name | a pointer to the name of the resource record |
| type | the type of the resource record |
| class | the class of the resource record |
| ttl | the ttl of the resource record |
| rdlength | the length of the rdata section of this resource record |
| decoded | if resource record is decoded (1) or not (0). |
| rdata | a pointer to the raw data (if decode = 0) or a structure (decoded =1) |
One can use this method to add a resource record to a DNS packet that is not supported by this library. For all RRs that this library support, we have a sdns_init_rr_*() function. If you have a new type to add, you can use this method to create it.
| sdns_rr_A * sdns_init_rr_A | ( | uint32_t | ipaddress | ) |
| sdns_rr_AAAA * sdns_init_rr_AAAA | ( | char * | aaaa | ) |
Initialize a structure of sdns_rr_AAAA.
| aaaa | pointer to the memory address that keeps the 16 bytes of IPv6 |
NOTE: do not free the 'aaaa' pointer after calling this method. This function does not copy the memory but use the pointer.
| sdns_rr_CAA * sdns_init_rr_CAA | ( | uint8_t | flag, |
| char * | tag, | ||
| uint8_t | tag_len, | ||
| char * | value, | ||
| uint16_t | value_len | ||
| ) |
Initialize a structure of sdns_rr_CAA.
| flag | one byte flag specified in Section 3 of RFC 6844 |
| tag | a pointer to tag value specified in RFC 6844 |
| tag_len | the length of the tag filed. max value can be 255. |
| value | a pointer to 'value' value specified in RFC 6844 @pram NOTE: Do not free the 'tag' and 'value' after calling this method. This function does not copy the memory but use a pointer to the memory you allocated. Make sure it's a heap-allocated memory to avoid memory leak. |
| sdns_rr_CNAME * sdns_init_rr_CNAME | ( | char * | cname | ) |
Initialize a structure of sdns_rr_CNAME.
| cname | pointer to the memory address that keeps the cname data |
NOTE: do not free the 'cname' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_L32 * sdns_init_rr_L32 | ( | uint16_t | preference, |
| uint32_t | locator32 | ||
| ) |
Initialize a structure of sdns_rr_L32.
| preference | 16bit unsigned integer showing the preference value of the L32 record |
| locator32 | 32bit unsigned integer for Locator32 |
| sdns_rr_L64 * sdns_init_rr_L64 | ( | uint16_t | preference, |
| char * | locator64 | ||
| ) |
Initialize a structure of sdns_rr_L64.
| preference | 16bit unsigned integer showing the preference value of the L64 record |
| locator64 | pointer to the memory address that keeps the Locator64 data |
NOTE: do not free the 'locator64' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
NOTE: locator64 is exactly 8 bytes based on RFC 6742
| sdns_rr_LP * sdns_init_rr_LP | ( | uint16_t | preference, |
| char * | fqdn | ||
| ) |
Initialize a structure of sdns_rr_LP.
| preference | 16bit unsigned integer showing the preference value of the LP record |
| fqdn | pointer to the memory address that keeps the fully-qualified-domain-name data |
NOTE: do not free the 'fqdn' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_MX * sdns_init_rr_MX | ( | uint16_t | preference, |
| char * | exchange | ||
| ) |
Initialize a structure of sdns_rr_MX.
| preference | a 16-bit integer for the prereference of the MX record |
| exchange | pointer to the memory address that keeps the 'exchange' data |
NOTE: do not free the 'exchange' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_NID * sdns_init_rr_NID | ( | uint16_t | preference, |
| char * | nodid | ||
| ) |
Initialize a structure of sdns_rr_NID.
| preference | 16bit unsigned integer showing the preference value of the NID record |
| nodid | pointer to the memory address that keeps the NodeId data |
NOTE: do not free the 'nodeid' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
NOTE: nodeid is exactly 8 bytes based on RFC 6742
| sdns_rr_NS * sdns_init_rr_NS | ( | char * | nsdname | ) |
Initialize a structure of sdns_rr_NS.
| nsdname | pointer to the memory address that keeps the nsdname data (e.g., ns1.google.com) |
NOTE: do not free the 'nsdname' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_PTR * sdns_init_rr_PTR | ( | char * | ptrdname | ) |
Initialize a structure of sdns_rr_PTR.
| ptrdname | pointer to the memory address that keeps the ptrdname data |
NOTE: do not free the 'ptrdname' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_SRV * sdns_init_rr_SRV | ( | uint16_t | Priority, |
| uint16_t | Weight, | ||
| uint16_t | Port, | ||
| char * | target | ||
| ) |
Initialize a structure of sdns_rr_SRV.
| Priority | 16-bit unsigned value for the priority of the SRV record |
| Weight | 16-bit unsigned value for the weight of the SRV record |
| Port | 16-bit unsigned value for the port of the SRV record |
| target | A pointer to the target value of the SRV record |
NOTE: do not free the 'target' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| sdns_rr_TXT * sdns_init_rr_TXT | ( | char * | data, |
| uint16_t | data_len | ||
| ) |
Initialize a structure of sdns_rr_TXT.
| data | pointer to the memory address that keeps the data |
| data_len | length of the data pointed by 'data' pointer |
NOTE: the 'data' pointer is not necessarily a nul-terminated string. That's why we need to know the length of the data.
NOTE: do not free the 'data' pointer after calling this method. This function does not copy the memory but use the pointer. Make sure it's a heap-allocated memory to avoid memory leak.
| int sdns_make_query | ( | sdns_context * | ctx, |
| sdns_rr_type | qtype, | ||
| sdns_q_class | cls, | ||
| char * | qname, | ||
| int | enable_edns0 | ||
| ) |
Creates a DNS question query.
| ctx | A pointer to the sdns_context structure created by sdns_init_context() |
| qtype | one of the possible values of sdns_rr_type |
| cls | one of the possible values of sdns_q_class |
| qname | a pointer to the question name. |
| enable_edns0 | a value of 0 or 1 specifying if the packet is EDNS0 aware or not. |
qname pointer must be a pointer to char* and not a local buffer. when you call sdns_free_context(), the function try to free() the qname.
In case the function returns a value other than 0, you can call sdns_error_string() to get the description of the error code.
| void sdns_rr_type_to_string | ( | uint16_t | t, |
| char * | buff | ||
| ) |
Gets the string representation of the TYPE tp in to buffer
| t | A 16bit integer, one of the possible values of sdns_rr_type |
| buff | A pointer to the user-provided buffer |
The buffer must be long enough to cover all types.
Currently, a buffer of length 20 is enough.
| int sdns_to_wire | ( | sdns_context * | ctx | ) |
Coverts a DNS context to binary format.
| ctx | A pointer to DNS context created by sdns_init_context(). |
This is one of the main APIs provided by this library. Whenever you want to send data to the socket, you must call this function first to create the binary data.
Look at the provided example for sdns_make_query() for more info.