aboutsummaryrefslogtreecommitdiff
path: root/src/dns.h
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-30 16:05:41 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-30 16:05:41 +0100
commitd2c641eb5b516783adfe2a236bc18412cd89af71 (patch)
tree17b9ebf08a749991bab83abd4771d05188b33049 /src/dns.h
parent3efdb35480dd6fa656d0728cab5c8dc76eaba24c (diff)
downloaddns-d2c641eb5b516783adfe2a236bc18412cd89af71.tar.gz
asdf
Diffstat (limited to 'src/dns.h')
-rw-r--r--src/dns.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/dns.h b/src/dns.h
index 5d8096e..8cba804 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -2,6 +2,69 @@
#include <stdint.h>
+//TODO remove
+#include <stdio.h>
+
+struct dns_header;
+
+struct dns_question;
+
+struct dns_answer;
+
+/**
+ * DNS Message struct
+ * */
+struct dns_message;
+
+struct dns_header {
+ uint16_t id;
+
+ uint8_t QR; //Query:0 Reply:1
+ uint8_t OPCODE; //Query:0 Iquery:1 Status:2
+ uint8_t AA; //Authorative answer
+ uint8_t TC; //Truncation
+ uint8_t RD; //Recursion Desired
+ uint8_t RA; //Recursion Available
+ uint8_t Z; //Unused
+ uint8_t RCODE; //Response Code
+
+ uint16_t question_count;
+ uint16_t answer_count;
+ uint16_t authorative_count;
+ uint16_t additional_count;
+};
+
+struct dns_question {
+ char* qname;
+ 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;
+ char* rdata;
+};
+
+struct dns_message {
+ struct dns_header header;
+
+ int qcount;
+ struct dns_question* question;
+
+ int acount;
+ struct dns_answer* answer;
+};
+
+/**
+ * Parse the packet in _buffer and populate the dns_message struct
+ * returns: 0 on success, !=0 on failure
+ * */
+int dns_parse_packet ( char* _buffer, int _bufflen, struct dns_message* _msg );
+
/**
* Convert a null terminated string containing a
* fqdn (eg server.example.com) to the binary format used by DNS records