sdns
low-level DNS library
Loading...
Searching...
No Matches
sdns.h
Go to the documentation of this file.
1
2#include <stdint.h>
3
4#ifndef __SDNS_H
5#define __SDNS_H
6
7#define TO_OUTPUT(A,B) do{if (NULL == A) {fprintf(stdout, B);}else{strcpy(A,B);}}while(0);
8
9#define UDP_PAYLOAD_SIZE 1232
10#define DNS_HEADER_LENGTH 12
11
12// define some error code constant
13#define SDNS_ERROR_MEMORY_ALLOC_FAILED -1
14#define SDNS_ERROR_BUFFER_TOO_SHORT -2
15#define SDNS_ERROR_QNAME_IS_NULL -3
16#define SDNS_ERROR_HOSTNAME_TOO_LONG -4
17#define SDNS_ERROR_WRONG_LABEL_SPECIFIED -5
18#define SDNS_ERROR_BUFFER_IS_NULL -6
19#define SDNS_ERROR_BUFFER_IS_SMALL -7
20#define SDNS_ERROR_INVALID_DNS_PACKET -8
21#define SDNS_ERROR_MORE_THAN_ONE_QUESTION_FOUND -9
22#define SDNS_ERROR_RR_NULL -10
23// these two are success code for encoding label
24#define SDNS_ERROR_ELSIMPLE -11
25#define SDNS_ERROR_ELCOMPRESSED -12
26
27#define SDNS_ERROR_LABEL_MAX_63 -13
30#define SDNS_ERROR_ILLEGAL_COMPRESSION -14
31#define SDNS_ERROR_RR_SECTION_MALFORMED -15
32#define SDNS_ERROR_INVALID_HEX_VALUE -16
33#define SDNS_ERROR_WRONG_INPUT_PARAMETER -17
34#define SDNS_ERROR_NSID_NOT_FOUND -18
35#define SDNS_ERROR_CLIENT_COOKIE_NOT_FOUND -19
36#define SDNS_ERROR_CHARACTER_STRING_TOO_LONG -20
37#define SDNS_ERROR_NO_ANSWER_FOUND -21
38#define SDNS_ERROR_CAN_NOT_READ_SECTION -22
39#define SDNS_ERROR_INVALID_IPv6_FOUND -23
40#define SDNS_ERROR_NO_AUTHORITY_FOUND -24
41#define SDNS_ERROR_NO_ADDITIONAL_FOUND -25
42#define SDNS_ERROR_ADDITIONAL_RR_OPT -26
43// define the section types
44#define DNS_SECTION_ANSWER 1
45#define DNS_SECTION_AUTHORITY 2
46#define DNS_SECTION_ADDITIONAL 3
47#define DNS_SECTION_QUESTION 4
48
49// define DNS masks
50#define SDNS_QR_MASK 0x8000
51#define SDNS_OPCODE_MASK 0x7800
52#define SDNS_AA_MASK 0x0400
53#define SDNS_TC_MASK 0x0200
54#define SDNS_RD_MASK 0x0100
55#define SDNS_RA_MASK 0x0080
56#define SDNS_Z_MASK 0x0040
57#define SDNS_AD_MASK 0x0020
58#define SDNS_CD_MASK 0x0010
59#define SDNS_RCODE_MASK 0x000F
60
61
62
74
75
76
105
121typedef struct {
122 char * qname;
123 uint16_t qtype;
124 uint16_t qclass;
126
127
155
158
159
160
172typedef struct{
173 uint32_t extended_rcode :8;
174 uint32_t version :8;
175 uint32_t DO :1;
176 uint32_t Z :15;
178
179
229struct _sdns_rr{
230 char * name;
231 uint16_t type;
232 union {
233 uint16_t class;
234 uint16_t udp_size;
235 };
236 union {
237 uint32_t ttl;
239 };
240 uint16_t rdlength;
241 union {
242 char * rdata;
244 void * psdns_rr;
245 };
246 uint8_t decoded;
247 struct _sdns_rr * next;
248};
249
251typedef struct _sdns_rr sdns_rr;
252
257typedef enum {
348 sdns_rr_type_DLV=32769
350
351
379
389
390
401
402
429typedef struct {
430 uint16_t id;
431 uint8_t qr :1;
432 uint8_t opcode :4;
433 uint8_t aa :1;
434 uint8_t tc :1;
435 uint8_t rd :1;
436 uint8_t ra :1;
437 uint8_t z :1;
438 uint8_t AD :1;
439 uint8_t CD :1;
440 uint8_t rcode:4;
441 uint16_t qdcount;
442 uint16_t ancount;
443 uint16_t nscount;
444 uint16_t arcount;
446
483
492
494typedef struct {
495 uint32_t address;
496} sdns_rr_A;
497
499typedef struct {
500 char * address;
502
510typedef struct {
511 uint8_t len;
512 char * content;
513} txt_data;
514
520
523
524
526typedef struct {
527 char * mname;
528 char * rname;
529 uint32_t serial;
530 uint32_t refresh;
531 uint32_t retry;
532 uint32_t expire;
533 uint32_t minimum;
535
536
538typedef struct {
539 uint16_t preference;
540 char * exchange;
542
544typedef struct{
545 char * NSDNAME;
547
548
550typedef struct{
551 char * PTRDNAME;
553
555typedef struct{
556 char * CNAME;
558
560typedef struct {
561 uint16_t inf_code;
562 char * extra_text;
563 uint16_t extra_text_len;
565
590typedef struct{
591 uint16_t type_covered;
592 uint8_t algorithm;
593 uint8_t labels;
594 uint32_t original_ttl;
597 uint16_t key_tag;
599 char * signature;
600 uint16_t signature_len;
602
603
608typedef struct{
609 uint16_t Priority;
610 uint16_t Weight;
611 uint16_t Port;
612 char * Target;
614
618typedef struct{
619 uint16_t Priority;
620 uint16_t Weight;
621 char * Target;
622 uint16_t target_len;
624
628typedef struct{
629 uint16_t Preference;
630 char * NodeId;
632
636typedef struct{
637 uint8_t cpu_len;
638 char * cpu;
639 uint8_t os_len;
640 char * os;
642
646typedef struct{
647 uint16_t Preference;
648 uint32_t Locator32;
650
651
655typedef struct{
656 uint16_t Preference;
657 char * Locator64;
659
660
664typedef struct{
665 uint16_t Preference;
666 char * FQDN;
668
669
673typedef struct{
674 uint8_t flag;
675 char * tag;
676 uint8_t tag_len;
677 uint16_t value_len;
678 char * value;
680
681
688typedef struct {
690 char * raw;
691 uint16_t raw_len;
692 char * cursor;
693 int err;
695
696
697
698// list of function declarations
699
747 sdns_q_class cls, char * qname, int enable_edns0);
748
749
750
764
765
795
796
807void sdns_error_string(int err, char ** err_buff);
808
809
810
820
821
831
832
872
873
887
888
889
907
908
909
910
917int check_if_qtype_is_valid(uint16_t qtype);
918
925int check_if_rrtype_is_valid(uint16_t qtype);
926
927
934int check_if_qclass_is_valid(uint16_t qclass);
935
942int check_if_rrclass_is_valid(uint16_t qclass);
943
952
969sdns_rr * sdns_init_rr(char * name, uint16_t type, uint16_t class, uint32_t ttl,
970 uint16_t rdlength, uint8_t decoded, void * rdata);
971
972
973
974
975
976int sdns_create_edns_option(uint16_t, uint16_t, char *, sdns_opt_rdata**);
977int sdns_add_edns(sdns_context * ctx, sdns_opt_rdata * opt);
978sdns_opt_rdata * sdns_create_edns0_ede(uint16_t info_code, char * extra_text, uint16_t extra_text_len);
979
980sdns_opt_rdata * sdns_create_edns0_nsid(char * nsid, uint16_t nsid_len);
981
982// add whatever function you want to ends0 section
984
985
986void * sdns_copy_rr_section(sdns_context *, sdns_rr*);
987void * sdns_decode_rr_section(sdns_context *, sdns_rr *);
988sdns_rr_A * sdns_decode_rr_A(sdns_context *, sdns_rr *);
989sdns_rr_AAAA * sdns_decode_rr_AAAA(sdns_context *, sdns_rr *);
990sdns_rr_TXT * sdns_decode_rr_TXT(sdns_context *, sdns_rr *);
991sdns_rr_SOA * sdns_decode_rr_SOA(sdns_context *, sdns_rr *);
992sdns_rr_MX * sdns_decode_rr_MX(sdns_context *, sdns_rr *);
993sdns_rr_NS * sdns_decode_rr_NS(sdns_context * ctx, sdns_rr * rr);
994sdns_rr_PTR * sdns_decode_rr_PTR(sdns_context * ctx, sdns_rr * rr);
995sdns_rr_CNAME* sdns_decode_rr_CNAME(sdns_context * ctx, sdns_rr * rr);
996sdns_rr_RRSIG * sdns_decode_rr_RRSIG(sdns_context * ctx, sdns_rr * rr);
997sdns_rr_SRV * sdns_decode_rr_SRV(sdns_context * ctx, sdns_rr * rr);
998sdns_rr_HINFO * sdns_decode_rr_HINFO(sdns_context * ctx, sdns_rr * rr);
999sdns_rr_URI * sdns_decode_rr_URI(sdns_context * ctx, sdns_rr* rr);
1000sdns_rr_NID * sdns_decode_rr_NID(sdns_context * ctx, sdns_rr* rr);
1001sdns_rr_L32 * sdns_decode_rr_L32(sdns_context * ctx, sdns_rr* rr);
1002sdns_rr_L64 * sdns_decode_rr_L64(sdns_context * ctx, sdns_rr* rr);
1003sdns_rr_LP * sdns_decode_rr_LP(sdns_context * ctx, sdns_rr* rr);
1004sdns_rr_CAA * sdns_decode_rr_CAA(sdns_context * ctx, sdns_rr * rr);
1005
1006sdns_opt_rdata * sdns_decode_rr_OPT(sdns_context * ctx, sdns_rr * rr);
1007
1008
1009
1019sdns_rr_A* sdns_init_rr_A(uint32_t ipaddress);
1020
1032
1033
1048sdns_rr_TXT* sdns_init_rr_TXT(char * data, uint16_t data_len);
1049
1063sdns_rr_SRV * sdns_init_rr_SRV(uint16_t Priority, uint16_t Weight, uint16_t Port, char * target);
1064
1065
1077sdns_rr_MX * sdns_init_rr_MX(uint16_t preference, char * exchange);
1078
1089sdns_rr_NS * sdns_init_rr_NS(char * nsdname);
1090
1091
1103
1104
1116
1129sdns_rr_NID * sdns_init_rr_NID(uint16_t preference, char * nodid);
1130
1131
1140sdns_rr_L32 * sdns_init_rr_L32(uint16_t preference, uint32_t locator32);
1141
1142
1156sdns_rr_L64 * sdns_init_rr_L64(uint16_t preference, char * locator64);
1157
1158
1170sdns_rr_LP * sdns_init_rr_LP(uint16_t preference, char * fqdn);
1171
1186sdns_rr_CAA * sdns_init_rr_CAA(uint8_t flag, char * tag, uint8_t tag_len, char * value, uint16_t value_len);
1187
1188
1189void sdns_free_opt_rdata(sdns_opt_rdata * opt);
1190sdns_opt_rdata * sdns_init_opt_rdata(void);
1191
1192sdns_rr_SRV * sdns_init_SRV(uint16_t, uint16_t, uint16_t, char *);
1193sdns_rr_URI * sdns_init_rr_URI(uint16_t, uint16_t, char *, uint16_t);
1194sdns_rr_RRSIG * sdns_init_rr_RRSIG(uint16_t, uint8_t, uint8_t, uint32_t, uint32_t, uint32_t, uint8_t, char *, char *, uint16_t);
1195sdns_rr_HINFO * sdns_init_rr_HINFO(uint8_t cpu_len, char * cpu, uint8_t os_len, char * os);
1196sdns_rr_SOA * sdns_init_rr_SOA(char * mname, char * rname, uint32_t expire, uint32_t minimum,
1197 uint32_t refresh, uint32_t retry, uint32_t serial);
1198
1205
1212
1219
1220
1227
1228
1235
1236
1243
1244
1251
1252
1253
1260
1261
1268
1269
1276
1277
1284
1285
1292
1293
1300
1301
1308
1309
1316
1317
1324
1331
1332
1333int sdns_create_edns_option(uint16_t, uint16_t, char *, sdns_opt_rdata**);
1334int sdns_add_edns(sdns_context * ctx, sdns_opt_rdata * opt);
1335
1336
1337
1350sdns_opt_rdata * sdns_create_edns0_ede(uint16_t info_code, char * extra_text, uint16_t extra_text_len);
1351
1368
1383sdns_opt_rdata * sdns_create_edns0_cookie(char * client_cookie, char * server_cookie, uint8_t server_cookie_len);
1384
1394void sdns_rr_type_to_string(uint16_t t, char * buff);
1395
1396
1406void sdns_class_to_string(uint16_t cls, char * buff);
1407
1408
1417
1418
1427
1428
1436
1437
1438
1439#endif
int check_if_rrtype_is_valid(uint16_t qtype)
This function checks if the given RR type is valid or not.
int sdns_to_wire(sdns_context *ctx)
Coverts a DNS context to binary format.
void sdns_free_rr_CNAME(sdns_rr_CNAME *cname)
Free the memory of the structure of type sdns_rr_CNAME.
void sdns_free_rr_URI(sdns_rr_URI *uri)
Free the memory of the structure of type sdns_rr_URI.
void sdns_free_section(sdns_rr *rr)
free a DNS resource record no matter of the type
void sdns_free_rr_SRV(sdns_rr_SRV *srv)
Free the memory of the structure of type sdns_rr_SRV.
sdns_rr_A * sdns_init_rr_A(uint32_t ipaddress)
Initialize a structure of sdns_rr_A.
sdns_q_class
Definition sdns.h:394
@ sdns_q_class_CS
RFC1035 - the CSNET.
Definition sdns.h:396
@ sdns_q_class_HS
RFC1035 - Hesiod.
Definition sdns.h:398
@ sdns_q_class_IN
RFC1035 - the Internet.
Definition sdns.h:395
@ sdns_q_class_STAR
RFC1035 - any class.
Definition sdns.h:399
@ sdns_q_class_CH
RFC1035 - the CHAOS class.
Definition sdns.h:397
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_free_rr_TXT(sdns_rr_TXT *txt)
Free the memory of the structure of type sdns_rr_TXT.
void sdns_free_context(sdns_context *ctx)
Frees the context allocated by sdns_init_context().
void sdns_free_rr_NS(sdns_rr_NS *ns)
Free the memory of the structure of type sdns_rr_NS.
sdns_rr_TXT * sdns_init_rr_TXT(char *data, uint16_t data_len)
Initialize a structure of sdns_rr_TXT.
int check_if_qclass_is_valid(uint16_t qclass)
This function checks if the given Question class is valid or not.
void sdns_free_rr_CAA(sdns_rr_CAA *caa)
Free the memory of the structure of type sdns_rr_CAA.
sdns_message * sdns_init_message(void)
Initialize a DNS message structure (sdns_message).
int sdns_convert_type_to_int(char *type)
Converts text type to its numerical value.
void sdns_free_rr_PTR(sdns_rr_PTR *ptr)
Free the memory of the structure of type sdns_rr_PTR.
void sdns_free_rr_SOA(sdns_rr_SOA *soa)
Free the memory of the structure of type sdns_rr_SOA.
sdns_rr_LP * sdns_init_rr_LP(uint16_t preference, char *fqdn)
Initialize a structure of sdns_rr_LP.
int sdns_add_answer_section(sdns_context *ctx, sdns_rr *rr)
Creates an answer section for the DNS packet.
void sdns_free_rr_A(sdns_rr_A *a)
Free the memory of the structure of type sdns_rr_A.
void sdns_free_rr_L32(sdns_rr_L32 *l32)
Free the memory of the structure of type sdns_rr_L32.
sdns_rr_L32 * sdns_init_rr_L32(uint16_t preference, uint32_t locator32)
Initialize a structure of sdns_rr_L32.
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.
sdns_ede_code
Definition sdns.h:451
@ sdns_ede_code_Unsupported_NSEC3_Iterations_Value
Unsupported NSEC3 Iterations Value.
Definition sdns.h:479
@ sdns_ede_code_DNSSEC_Bogus
The resolver attempted to perform DNSSEC validation, but validation ended in the Bogus state.
Definition sdns.h:458
@ sdns_ede_code_Stale_Answer
Stale Answer.
Definition sdns.h:455
@ sdns_ede_code_Signature_Expired
Signature Expired.
Definition sdns.h:459
@ sdns_ede_code_Blocked
Blocked.
Definition sdns.h:467
@ sdns_ede_code_Filtered
Filtered.
Definition sdns.h:469
@ sdns_ede_code_Prohibited
Prohibited.
Definition sdns.h:470
@ sdns_ede_code_Signature_Not_Yet_Valid
Signature Not Yet Valid.
Definition sdns.h:460
@ sdns_ede_code_Not_Supported
Not Supported.
Definition sdns.h:473
@ sdns_ede_code_Too_Early
Too Early
Definition sdns.h:478
@ sdns_ede_code_Signature_Expired_before_Valid
Signature Expired before Valid.
Definition sdns.h:477
@ sdns_ede_code_RRSIGs_Missing
RRSIGs Missing.
Definition sdns.h:462
@ sdns_ede_code_Not_Ready
The server is unable to answer the query, as it was not fully functional when the query was received.
Definition sdns.h:466
@ sdns_ede_code_Unsupported_DS_Digest_Type
Unsupported DS Digest Type.
Definition sdns.h:454
@ sdns_ede_code_DNSSEC_Indeterminate
DNSSEC Indeterminate.
Definition sdns.h:457
@ sdns_ede_code_No_Reachable_Authority
No Reachable Authority.
Definition sdns.h:474
@ sdns_ede_code_NSEC_Missing
NSEC Missing.
Definition sdns.h:464
@ sdns_ede_code_Forged_Answer
For policy reasons (legal obligation or malware filtering, for instance), an answer was forged.
Definition sdns.h:456
@ sdns_ede_code_Censored
Censored.
Definition sdns.h:468
@ sdns_ede_code_Unable_to_conform_to_policy
Unable to conform to policy.
Definition sdns.h:480
@ sdns_ede_code_Unsupported_DNSKEY_Algorithm
Unsupported DNSKEY Algorithm.
Definition sdns.h:453
@ sdns_ede_code_No_Zone_Key_Bit_Set
The resolver attempted to perform DNSSEC validation, but no Zone Key Bit was set in a DNSKEY.
Definition sdns.h:463
@ sdns_ede_code_Network_Error
Network Error.
Definition sdns.h:475
@ sdns_ede_code_Not_Authoritative
Not Authoritative.
Definition sdns.h:472
@ sdns_ede_code_Other_Error
Other.
Definition sdns.h:452
@ sdns_ede_code_Synthesized
Synthesized.
Definition sdns.h:481
@ sdns_ede_code_Cached_Error
Cached Error.
Definition sdns.h:465
@ sdns_ede_code_Invalid_Data
Invalid Data.
Definition sdns.h:476
@ sdns_ede_code_Stale_NXDomain_Answer
Stale NXDOMAIN Answer.
Definition sdns.h:471
@ sdns_ede_code_DNSKEY_Missing
A DS record existed at a parent, but no supported matching DNSKEY record could be found for the child...
Definition sdns.h:461
void sdns_free_rr_LP(sdns_rr_LP *lp)
Free the memory of the structure of type sdns_rr_LP.
void sdns_free_rr_MX(sdns_rr_MX *mx)
Free the memory of the structure of type sdns_rr_MX.
sdns_rr_class
Definition sdns.h:383
@ sdns_rr_class_CS
RFC1035 - the CSNET.
Definition sdns.h:385
@ sdns_rr_class_CH
RFC1035 - the CHAOS class.
Definition sdns.h:386
@ sdns_rr_class_IN
RFC1035 - the Internet.
Definition sdns.h:384
@ sdns_rr_class_HS
RFC1035 - Hesiod.
Definition sdns.h:387
sdns_rr_NID * sdns_init_rr_NID(uint16_t preference, char *nodid)
Initialize a structure of sdns_rr_NID.
int check_if_qtype_is_valid(uint16_t qtype)
This function checks if the given qtype code is valid or not.
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.
sdns_context * sdns_init_context(void)
Initialize and create a new DNS context.
sdns_rr_MX * sdns_init_rr_MX(uint16_t preference, char *exchange)
Initialize a structure of sdns_rr_MX.
sdns_opcode
Definition sdns.h:66
@ sdns_opcode_Update
RFC2136.
Definition sdns.h:71
@ sdns_opcode_IQuery
RFC1035.
Definition sdns.h:68
@ sdns_opcode_Status
RFC1035.
Definition sdns.h:69
@ sdns_opcode_Query
RFC1035.
Definition sdns.h:67
@ sdns_opcode_DSO
RFC8490.
Definition sdns.h:72
@ sdns_opcode_Notify
RFC1996.
Definition sdns.h:70
int check_if_rrclass_is_valid(uint16_t qclass)
This function checks if the given RR class is valid or not.
sdns_rcode
Definition sdns.h:81
@ sdns_rcode_YXRRSet
RFC2136.
Definition sdns.h:89
@ sdns_rcode_BADVERS
Bad OPT Version RFC6891.
Definition sdns.h:94
@ sdns_rcode_Reserved
Reserved, can be allocated by Standards Action RFC6895.
Definition sdns.h:103
@ sdns_rcode_BADCOOKIE
Bad/missing Server Cookie RFC7873.
Definition sdns.h:102
@ sdns_rcode_NXRRSet
RFC2136.
Definition sdns.h:90
@ sdns_rcode_NotZone
RFC2136.
Definition sdns.h:92
@ sdns_rcode_BADALG
Algorithm not supported RFC2930.
Definition sdns.h:100
@ sdns_rcode_FormErr
RFC1035.
Definition sdns.h:83
@ sdns_rcode_BADTRUNC
Bad Truncation RFC8945.
Definition sdns.h:101
@ sdns_rcode_NoError
RFC1035.
Definition sdns.h:82
@ sdns_rcode_ServFail
RFC1035.
Definition sdns.h:84
@ sdns_rcode_BADSIG
TSIG Signature Failure RFC8945.
Definition sdns.h:95
@ sdns_rcode_BADKEY
Key not recognized RFC8945.
Definition sdns.h:96
@ sdns_rcode_NotAuth
RFC2136, RFC8945.
Definition sdns.h:91
@ sdns_rcode_BADTIME
Signature out of time window RFC8945.
Definition sdns.h:97
@ sdns_rcode_YXDomain
RFC2136.
Definition sdns.h:88
@ sdns_rcode_BADNAME
Duplicate key name RFC2930.
Definition sdns.h:99
@ sdns_rcode_NotImp
RFC1035.
Definition sdns.h:86
@ sdns_rcode_BADMODE
Bad TKEY Mode RFC2930.
Definition sdns.h:98
@ sdns_rcode_DSOTYPENI
RFC8490.
Definition sdns.h:93
@ sdns_rcode_NXDomain
RFC1035.
Definition sdns.h:85
@ sdns_rcode_Refused
RFC1035.
Definition sdns.h:87
void sdns_rr_type_to_string(uint16_t t, char *buff)
Gets the string representation of the TYPE tp in to buffer
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_CNAME * sdns_init_rr_CNAME(char *cname)
Initialize a structure of sdns_rr_CNAME.
sdns_rr_AAAA * sdns_init_rr_AAAA(char *aaaa)
Initialize a structure of sdns_rr_AAAA.
void sdns_free_rr_RRSIG(sdns_rr_RRSIG *rrsig)
Free the memory of the structure of type sdns_rr_RRSIG.
void sdns_free_rr_L64(sdns_rr_L64 *l64)
Free the memory of the structure of type sdns_rr_L64.
int sdns_convert_class_to_int(char *cls)
Converts text class to its numerical value.
sdns_rr_type
Definition sdns.h:257
@ sdns_rr_type_AAAA
RFC3596 - AAAA record.
Definition sdns.h:285
@ sdns_rr_type_NXT
Next Domain (OBSOLETE) RFC2535, RFC3755.
Definition sdns.h:287
@ sdns_rr_type_NULL
RFC1035 - a null RR.
Definition sdns.h:267
@ sdns_rr_type_SVCB
General-purpose service binding RFC9460.
Definition sdns.h:320
@ sdns_rr_type_SPF
RFC7208.
Definition sdns.h:322
@ sdns_rr_type_CDNSKEY
DNSKEY(s) the Child wants reflected in DS RFC7344.
Definition sdns.h:316
@ sdns_rr_type_AXFR
RFC1035 - request for transfer of entire zone.
Definition sdns.h:336
@ sdns_rr_type_HTTPS
SVCB-compatible type for use with HTTP RFC9460.
Definition sdns.h:321
@ sdns_rr_type_RT
for Route Through RFC1183
Definition sdns.h:278
@ sdns_rr_type_NINFO
NINFO.
Definition sdns.h:312
@ sdns_rr_type_NID
RFC6742.
Definition sdns.h:327
@ sdns_rr_type_UINFO
IANA-Reserved.
Definition sdns.h:323
@ sdns_rr_type_TXT
RFC1035 - text strings.
Definition sdns.h:273
@ sdns_rr_type_DHCID
DHCID RFC4701.
Definition sdns.h:306
@ sdns_rr_type_NSAP_PTR
for domain name pointer, NSAP style
Definition sdns.h:280
@ sdns_rr_type_MB
RFC1035 - mailbox domain name.
Definition sdns.h:264
@ sdns_rr_type_CERT
CERT.
Definition sdns.h:294
@ sdns_rr_type_APL
APL.
Definition sdns.h:299
@ sdns_rr_type_GPOS
Geographical Position RFC1712.
Definition sdns.h:284
@ sdns_rr_type_CSYNC
Child-To-Parent Synchronization RFC7477.
Definition sdns.h:318
@ sdns_rr_type_AVC
Application Visibility and Control.
Definition sdns.h:342
@ sdns_rr_type_NSAP
for NSAP address, NSAP style A record (deprecated)
Definition sdns.h:279
@ sdns_rr_type_SINK
SINK.
Definition sdns.h:297
@ sdns_rr_type_RP
for Responsible Person RFC1183
Definition sdns.h:274
@ sdns_rr_type_WKS
RFC1035 - a well known service description.
Definition sdns.h:268
@ sdns_rr_type_CNAME
RFC1035 - canonical name.
Definition sdns.h:262
@ sdns_rr_type_PX
X.400 mail mapping information FC2163.
Definition sdns.h:283
@ sdns_rr_type_CAA
Certification Authority Restriction [RFC8659].
Definition sdns.h:341
@ sdns_rr_type_OPENPGPKEY
OpenPGP Key RFC7929.
Definition sdns.h:317
@ sdns_rr_type_DLV
DNSSEC Lookaside Validation (OBSOLETE)
Definition sdns.h:348
@ sdns_rr_type_MX
RFC1035 - mail exchange.
Definition sdns.h:272
@ sdns_rr_type_TSIG
Transaction Signature RFC8945.
Definition sdns.h:334
@ sdns_rr_type_MAILA
RFC1035 - request for mail agent RRs.
Definition sdns.h:338
@ sdns_rr_type_SSHFP
SSH Key Fingerprint RFC4255.
Definition sdns.h:301
@ sdns_rr_type_TLSA
TLSA [RFC6698.
Definition sdns.h:309
@ sdns_rr_type_IXFR
incremental transfer RFC1995
Definition sdns.h:335
@ sdns_rr_type_AMTRELAY
Automatic Multicast Tunneling Relay [RFC8777].
Definition sdns.h:344
@ sdns_rr_type_EUI48
an EUI-48 address RFC7043
Definition sdns.h:331
@ sdns_rr_type_ISDN
for ISDN address RFC1183
Definition sdns.h:277
@ sdns_rr_type_MD
RFC1035 - mail destination record.
Definition sdns.h:260
@ sdns_rr_type_KEY
for security key RFC2536, RFC2539, RFC3110, RFC4034
Definition sdns.h:282
@ sdns_rr_type_DS
Delegation Signer RFC4034.
Definition sdns.h:300
@ sdns_rr_type_RKEY
RKEY.
Definition sdns.h:313
@ sdns_rr_type_NSEC3
NSEC3 RFC5155, RFC9077.
Definition sdns.h:307
@ sdns_rr_type_TA
DNSSEC Trust Authorities.
Definition sdns.h:347
@ sdns_rr_type_NSEC
NSEC RFC4034, RFC9077.
Definition sdns.h:304
@ sdns_rr_type_MG
RFC1035 - mail group member.
Definition sdns.h:265
@ sdns_rr_type_TKEY
Transaction Key RFC2930.
Definition sdns.h:333
@ sdns_rr_type_X25
for X.25 PSDN address RFC1183
Definition sdns.h:276
@ sdns_rr_type_GID
IANA-Reserved.
Definition sdns.h:325
@ sdns_rr_type_ZONEMD
Message Digest Over Zone Data RFC8976.
Definition sdns.h:319
@ sdns_rr_type_NS
RFC1035 - NS record.
Definition sdns.h:259
@ sdns_rr_type_SMIMEA
S/MIME cert association RFC8162.
Definition sdns.h:310
@ sdns_rr_type_SOA
RFC1035 - start of a zone of authority.
Definition sdns.h:263
@ sdns_rr_type_URI
URI RFC7553.
Definition sdns.h:340
@ sdns_rr_type_NSEC3PARAM
NSEC3PARAM [RFC5155.
Definition sdns.h:308
@ sdns_rr_type_RESINFO
Resolver Information as Key/Value Pairs.
Definition sdns.h:345
@ sdns_rr_type_MAILB
RFC1035 - request for mailbox related records.
Definition sdns.h:337
@ sdns_rr_type_HINFO
RFC1035 - host information.
Definition sdns.h:270
@ sdns_rr_type_PTR
RFC1035 - a domain name pointer.
Definition sdns.h:269
@ sdns_rr_type_EID
Endpoint Identifier.
Definition sdns.h:288
@ sdns_rr_type_WALLET
Public wallet address.
Definition sdns.h:346
@ sdns_rr_type_A
RFC1035 - A record.
Definition sdns.h:258
@ sdns_rr_type_HIP
Host Identity Protocol RFC8005.
Definition sdns.h:311
@ sdns_rr_type_TALINK
Trust Anchor LINK.
Definition sdns.h:314
@ sdns_rr_type_UNSPEC
IANA-Reserved.
Definition sdns.h:326
@ sdns_rr_type_DNSKEY
DNSKEY RFC4034.
Definition sdns.h:305
@ sdns_rr_type_NIMLOC
Nimrod Locator.
Definition sdns.h:289
@ sdns_rr_type_EUI64
an EUI-64 address RFC7043
Definition sdns.h:332
@ sdns_rr_type_DNAME
DNAME.
Definition sdns.h:296
@ sdns_rr_type_MR
RFC1035 - mail rename domain name.
Definition sdns.h:266
@ sdns_rr_type_MF
RFC1035 - mail forwarder record.
Definition sdns.h:261
@ sdns_rr_type_SIG
for security signature RFC2536, RFC2931, RFC3110, RFC4034
Definition sdns.h:281
@ sdns_rr_type_RRSIG
RRSIG RFC4034.
Definition sdns.h:303
@ sdns_rr_type_NAPTR
Naming Authority Pointer.
Definition sdns.h:292
@ sdns_rr_type_AFSDB
for AFS Data Base location RFC1183, RFC5864
Definition sdns.h:275
@ sdns_rr_type_DOA
Digital Object Architecture.
Definition sdns.h:343
@ sdns_rr_type_L64
RFC6742.
Definition sdns.h:329
@ sdns_rr_type_LOC
Location Information RFC1876.
Definition sdns.h:286
@ sdns_rr_type_SRV
Server Selection.
Definition sdns.h:290
@ sdns_rr_type_ATMA
ATM Address.
Definition sdns.h:291
@ sdns_rr_type_KX
Key Exchanger.
Definition sdns.h:293
@ sdns_rr_type_UID
IANA-Reserved.
Definition sdns.h:324
@ sdns_rr_type_LP
RFC6742.
Definition sdns.h:330
@ sdns_rr_type_IPSECKEY
IPSECKEY RFC4025.
Definition sdns.h:302
@ sdns_rr_type_L32
RFC6742.
Definition sdns.h:328
@ sdns_rr_type_CDS
Child DS.
Definition sdns.h:315
@ sdns_rr_type_A6
A6 (OBSOLETE - use AAAA)
Definition sdns.h:295
@ sdns_rr_type_OPT
RFC6891 - option RR for ends.
Definition sdns.h:298
@ sdns_rr_type_star
RFC1035 - request for all records.
Definition sdns.h:339
@ sdns_rr_type_MINFO
RFC1035 - mailbox or mail list information.
Definition sdns.h:271
void sdns_class_to_string(uint16_t cls, char *buff)
Gets the string representation of the CLASS cls in to buffer
sdns_rr_NS * sdns_init_rr_NS(char *nsdname)
Initialize a structure of sdns_rr_NS.
void sdns_free_rr_NID(sdns_rr_NID *nid)
Free the memory of the structure of type sdns_rr_NID.
sdns_rr_PTR * sdns_init_rr_PTR(char *ptrdname)
Initialize a structure of sdns_rr_PTR.
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_free_rr_AAAA(sdns_rr_AAAA *aaaa)
Free the memory of the structure of type sdns_rr_AAAA.
int sdns_add_authority_section(sdns_context *ctx, sdns_rr *rr)
Adds a new RR to the authority section of the DNS packet.
sdns_edns0_option_code
Definition sdns.h:356
@ sdns_edns0_option_code_DeviceID
DeviceID.
Definition sdns.h:377
@ sdns_edns0_option_code_edns_tcp_keepalive
edns-tcp-keepalive RFC7828
Definition sdns.h:368
@ sdns_edns0_option_code_LLQ
LLQ RFC8764.
Definition sdns.h:358
@ sdns_edns0_option_code_N3U
N3U RFC6975.
Definition sdns.h:364
@ sdns_edns0_option_code_edns_key_tag
edns-key-tag RFC8145
Definition sdns.h:371
@ sdns_edns0_option_code_edns_client_subnet
edns-client-subnet RFC7871
Definition sdns.h:365
@ sdns_edns0_option_code_Update_Lease
Update Lease.
Definition sdns.h:359
@ sdns_edns0_option_code_EDNS_Server_Tag
EDNS-Server-Tag.
Definition sdns.h:374
@ sdns_edns0_option_code_Extended_DNS_Error
Extended DNS Error RFC8914.
Definition sdns.h:372
@ sdns_edns0_option_code_DAU
DAU RFC6975.
Definition sdns.h:362
@ sdns_edns0_option_code_COOKIE
COOKIE RFC7873.
Definition sdns.h:367
@ sdns_edns0_option_code_CHAIN
CHAIN RFC7901.
Definition sdns.h:370
@ sdns_edns0_option_code_NSID
NSID RFC5001.
Definition sdns.h:360
@ sdns_edns0_option_code_Umbrella_Ident
Umbrella Ident.
Definition sdns.h:376
@ sdns_edns0_option_code_EDNS_EXPIRE
EDNS EXPIRE RFC7314.
Definition sdns.h:366
@ sdns_edns0_option_code_Reserved0
Reserved RFC6891.
Definition sdns.h:357
@ sdns_edns0_option_code_Padding
Padding RFC7830.
Definition sdns.h:369
@ sdns_edns0_option_code_Reserved4
Reserved.
Definition sdns.h:361
@ sdns_edns0_option_code_Report_Channel
Report-Channel RFC9567.
Definition sdns.h:375
@ sdns_edns0_option_code_EDNS_Client_Tag
EDNS-Client-Tag.
Definition sdns.h:373
@ sdns_edns0_option_code_DHU
DHU RFC6975.
Definition sdns.h:363
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_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_add_additional_section(sdns_context *ctx, sdns_rr *rr)
Adds a new RR to the additional section of the DNS packet.
void sdns_error_string(int err, char **err_buff)
Coverts error codes to a string.
void sdns_free_rr_HINFO(sdns_rr_HINFO *hinfo)
Free the memory of the structure of type sdns_rr_HINFO.
sdns_rr_L64 * sdns_init_rr_L64(uint16_t preference, char *locator64)
Initialize a structure of sdns_rr_L64.
int sdns_from_wire(sdns_context *ctx)
Converts the raw data received from socket (bytes) to a DNS packet.
Definition sdns.h:149
uint16_t option_code
16bit option code
Definition sdns.h:150
struct _sdns_opt_rdata * next
non-rfc field. Just to keep the reference to the next option structure
Definition sdns.h:153
char * option_data
Pointer to the option data.
Definition sdns.h:152
uint16_t option_length
16bit option length specifies the length of the option data
Definition sdns.h:151
Definition sdns.h:516
struct _sdns_rr_TXT * next
keep the reference to the next structure
Definition sdns.h:518
txt_data character_string
see :txt_data for more info
Definition sdns.h:517
Definition sdns.h:229
uint16_t type
RFC1035 - RR type code.
Definition sdns.h:231
void * psdns_rr
this is not DNS-RFC. It's just a reference for our library
Definition sdns.h:244
uint16_t rdlength
RFC1035 - length of the RDATA field.
Definition sdns.h:240
uint16_t udp_size
size of the UDP packet
Definition sdns.h:234
sdns_opt_ttl opt_ttl
will expand to sdns_opt_ttl if type=OPT
Definition sdns.h:238
uint8_t decoded
this is not DNS-RFC. it's just a flag to know if the rdata is decoded or not
Definition sdns.h:246
uint32_t ttl
Time To Live.
Definition sdns.h:237
struct _sdns_rr * next
non-rfc field, just keep the reference to the next structure (linked-list)
Definition sdns.h:247
sdns_opt_rdata * opt_rdata
if type=OPT, this will refer to sdns_opt_rdata structure
Definition sdns.h:243
char * name
RFC1035 - domain name.
Definition sdns.h:230
char * rdata
resource record data (for all RRs except for OPT)
Definition sdns.h:242
Definition sdns.h:688
sdns_message * msg
This is the DNS packet.
Definition sdns.h:689
char * cursor
This cursor keeps the position of the pointer in raw data.
Definition sdns.h:692
uint16_t raw_len
Length of the raw data we received from socket.
Definition sdns.h:691
int err
This shows the last error code after any operation on the context.
Definition sdns.h:693
char * raw
The raw bytes we received from socket.
Definition sdns.h:690
Definition sdns.h:429
uint8_t qr
RFC1035: one bit if the msg is query(0) or response(1)
Definition sdns.h:431
uint16_t id
RFC1035: 16-bit identifier.
Definition sdns.h:430
uint16_t nscount
RFC1035: Number of entries in authority section.
Definition sdns.h:443
uint8_t rcode
RFC1035: Response code.
Definition sdns.h:440
uint8_t aa
RFC1035: 1-bit if this is an authoritative answer.
Definition sdns.h:433
uint8_t z
RFC1035: Reserved for future use.
Definition sdns.h:437
uint16_t arcount
RFC1035: Number of entries in additional section.
Definition sdns.h:444
uint8_t ra
RFC1035: Recursion Available.
Definition sdns.h:436
uint16_t ancount
RFC1035: Number of entries in answer section.
Definition sdns.h:442
uint8_t rd
RFC1035: Recursion Desired.
Definition sdns.h:435
uint8_t tc
RFC1035: 1-bit TrunCation.
Definition sdns.h:434
uint16_t qdcount
RFC1035: Number of entries in question section.
Definition sdns.h:441
uint8_t AD
RFC2535: Section 6.1: authentic data.
Definition sdns.h:438
uint8_t opcode
RFC1035: 4-bit specifies the kind of query in the message.
Definition sdns.h:432
uint8_t CD
RFC2535: Section 6.1: checking disabled.
Definition sdns.h:439
Definition sdns.h:485
sdns_rr * authority
Authority section of a DNS packet.
Definition sdns.h:489
sdns_rr * answer
Answer section of a DNS packet.
Definition sdns.h:488
sdns_header header
See sdns_header for more info.
Definition sdns.h:486
sdns_rr * additional
Additional section of a DNS packet.
Definition sdns.h:490
sdns_question question
See sdns_question for more info.
Definition sdns.h:487
Definition sdns.h:172
uint32_t Z
Reserved (must be zero always)
Definition sdns.h:176
uint32_t DO
DNSSEC OK bit.
Definition sdns.h:175
uint32_t version
version of the edns (it's zero)
Definition sdns.h:174
uint32_t extended_rcode
extended response code
Definition sdns.h:173
Definition sdns.h:121
uint16_t qtype
RFC1035 - two octet, type of the query.
Definition sdns.h:123
uint16_t qclass
RFC1035 - two octet, class of the query.
Definition sdns.h:124
char * qname
RFC1035 - the domain name.
Definition sdns.h:122
Definition sdns.h:499
char * address
IPv6 address but we keep it as a sequence of bytes (exactly 16 bytes)
Definition sdns.h:500
Definition sdns.h:494
uint32_t address
IPv4 address (only one address)
Definition sdns.h:495
Definition sdns.h:673
uint8_t tag_len
length of the tag field (non-RFC field). tag is not null-terminated necessarily
Definition sdns.h:676
uint8_t flag
8 bit flag
Definition sdns.h:674
char * tag
pointer to tag
Definition sdns.h:675
uint16_t value_len
length of the value filed (non-RFC field). value is not null-terminated necessarily
Definition sdns.h:677
char * value
pointer to value
Definition sdns.h:678
Definition sdns.h:555
char * CNAME
A <domain-name> which specifies the canonical or primary name for the owner.
Definition sdns.h:556
Definition sdns.h:636
char * cpu
CPU information.
Definition sdns.h:638
uint8_t cpu_len
non-rfc: just to have the length of the CPU field
Definition sdns.h:637
uint8_t os_len
non-rfc: just to have the length of the OS field
Definition sdns.h:639
char * os
OS information.
Definition sdns.h:640
Definition sdns.h:646
uint32_t Locator32
locator32 is exactly 32 bit so we can have a uint32 type to cover it
Definition sdns.h:648
uint16_t Preference
a 16-bit preference field
Definition sdns.h:647
Definition sdns.h:655
char * Locator64
Locator64 is exactly 64 bit (8bytes)
Definition sdns.h:657
uint16_t Preference
a 16-bit Preference field
Definition sdns.h:656
Definition sdns.h:664
char * FQDN
FQDN is a variable length field contains the DNS target name that is used to reference L32 and/or L64...
Definition sdns.h:666
uint16_t Preference
a 16-bit Preference field
Definition sdns.h:665
Definition sdns.h:538
char * exchange
A <domain-name> which specifies a host willing to act as a mail exchange for the owner name.
Definition sdns.h:540
uint16_t preference
A 16 bit integer which specifies the preference given to this RR among others at the same owner.
Definition sdns.h:539
Definition sdns.h:628
uint16_t Preference
indicates the owner name's relative preference
Definition sdns.h:629
char * NodeId
NodeID field is an unsigned 64-bit value in network byte order (len=8bytes)
Definition sdns.h:630
Definition sdns.h:544
char * NSDNAME
A <domain-name> which specifies a host which should be authoritative for the specified class and doma...
Definition sdns.h:545
Definition sdns.h:560
uint16_t extra_text_len
Section 2, RFC8914: the length MUST be derived from the OPTION-LENGTH field.
Definition sdns.h:563
uint16_t inf_code
One of the values in sdns_ede_code.
Definition sdns.h:561
char * extra_text
Section 2, RFC8914 says this is null-terminated but MUST NOT be assumed to be.
Definition sdns.h:562
Definition sdns.h:550
char * PTRDNAME
A <domain-name> which points to some location in the domain name space.
Definition sdns.h:551
Definition sdns.h:590
uint32_t signature_expiration
validity period for the signature
Definition sdns.h:595
uint16_t signature_len
This is just a helper not an RFC standard field.
Definition sdns.h:600
char * signature
the cryptographic signature that covers the RRSIG RDATA and the RRset
Definition sdns.h:599
uint8_t labels
specifies the number of labels in the original RRSIG RR owner name
Definition sdns.h:593
uint8_t algorithm
identifies the cryptographic algorithm used to create the signature
Definition sdns.h:592
uint16_t key_tag
key tag value of the DNSKEY RR that validates this signature
Definition sdns.h:597
uint32_t original_ttl
specifies the TTL of the covered RRset as it appears in the authoritative zone
Definition sdns.h:594
uint16_t type_covered
identifies the type of the RRset that is covered by this RRSIG record
Definition sdns.h:591
char * signers_name
the owner name of the DNSKEY RR that a validator is supposed to use to validate this signature
Definition sdns.h:598
uint32_t signature_inception
validity period for the signature
Definition sdns.h:596
Definition sdns.h:526
char * rname
mailbox of the responsible person
Definition sdns.h:528
uint32_t retry
elapse before a failed refresh should be retried
Definition sdns.h:531
char * mname
Primary name server.
Definition sdns.h:527
uint32_t expire
upper limit on the time interval that can elapse before the zone is no longer authoritative
Definition sdns.h:532
uint32_t minimum
minimum TTL field that should be exported with any RR from this zone
Definition sdns.h:533
uint32_t refresh
time interval before the zone should be refreshed
Definition sdns.h:530
uint32_t serial
version number of the original copy of the zone
Definition sdns.h:529
Definition sdns.h:608
uint16_t Port
The port on this target host of this service.
Definition sdns.h:611
uint16_t Priority
The priority of this target host.
Definition sdns.h:609
char * Target
RFC2782: the name compression can not be applied to this name.
Definition sdns.h:612
uint16_t Weight
A server selection mechanism.
Definition sdns.h:610
Definition sdns.h:618
char * Target
I didn't find any text in RFC saying this must be a human-readable string!
Definition sdns.h:621
uint16_t Weight
This field holds the server selection mechanism.
Definition sdns.h:620
uint16_t target_len
non-rfc filed. Just used as a helper to know the length of the Target filed
Definition sdns.h:622
uint16_t Priority
his field holds the priority of the target URI in this RR
Definition sdns.h:619
Definition sdns.h:510
uint8_t len
length of the content filed
Definition sdns.h:511
char * content
content filed is not nul-terminated necessarily
Definition sdns.h:512