aboutsummaryrefslogtreecommitdiff
path: root/src/dns.h
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-12-02 22:53:38 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-12-02 22:53:38 +0100
commitd84a301a63c768afa3aafeede302e809af93f351 (patch)
tree8e7bf34b73c430fef4efff5f290858a371408aa1 /src/dns.h
parent1629c3621e02a8e176172f44a72d155030172d35 (diff)
downloaddns-d84a301a63c768afa3aafeede302e809af93f351.tar.gz
memory leak fixes, now answers
removed forking to improve performance fixed memory leaks added header construct function now return MXDOMAIN to all valid DNS queries
Diffstat (limited to 'src/dns.h')
-rw-r--r--src/dns.h61
1 files changed, 53 insertions, 8 deletions
diff --git a/src/dns.h b/src/dns.h
index f93480e..fe871e0 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -12,18 +12,49 @@
//TODO remove
#include <stdio.h>
+//Resource Records
+#define RR_A 1
+#define RR_NS 2
+#define RR_CNAME 5
+#define RR_SOA 6
+#define RR_MX 15
+#define RR_TXT 16
+#define RR_AAAA 28
+#define RR_SRV 33
+
+//Record Classes
+#define CL_IN 1 //Internet
+#define CL_CS 2 //CSNET (Onsolete)
+#define CL_CH 3 //CHAOS
+#define CL_HS 4 //Hesiod
+
+//OPCODES
+#define OP_Q 0 //Query
+#define OP_IQ 1 //Inverse Query
+#define OP_STAT 2 //Status request
+
+//Responsecode
+#define RCODE_NOERR 0
+#define RCODE_FORMAT 1
+#define RCODE_SERVFAIL 2
+#define RCODE_NAMEERR 3
+#define RCODE_NI 4 //Not implemented
+#define RCODE_REFUSED 5
+
+#define FLIP_BYTES(u) (((0x00FF & u) << 8) | ((0xFF00 & u) >> 8))
+
/**
* Data is COPIED
* */
struct dns_header;
/**
- * Data is REFERENCED
+ * QNAME is REFERENCED
* */
struct dns_question;
/**
- * Data is REFERENCED
+ * NAME is REFERENCED
* */
struct dns_answer;
@@ -55,16 +86,16 @@ struct dns_header {
struct dns_question {
const char* qname;
- const uint16_t* qtype;
- uint16_t* qclass;
+ uint16_t qtype;
+ uint16_t qclass;
};
struct dns_answer {
char* name; //in qname format
- uint16_t* type;
- uint16_t* class;
- uint32_t* ttl;
- uint16_t* rdlength;
+ uint16_t type;
+ uint16_t class;
+ uint32_t ttl;
+ uint16_t rdlength;
char* rdata;
};
@@ -78,10 +109,24 @@ struct dns_message {
struct dns_answer* answer;
};
+int dns_construct_header (
+ struct dns_header* _header,
+ char* _buffer,
+ int _bufflen
+ );
+
+/**
+ * Frees all malloced memory
+ * */
+int dns_destroy_struct ( struct dns_message* _msg );
+
/**
* Parse the packet in _buffer and populate the dns_message struct
* Struct may still be written to on failure but contents are invalid
* returns: 0 on success, !=0 on failure
+ *
+ * ONLY WRITES QUESTION SECTION. ALL OTHER ARE IGNORED
+ *
* */
int dns_parse_packet ( char* _buffer, int _bufflen, struct dns_message* _msg );