wip
This commit is contained in:
1 parent
af592f2082
commit
c0b549631c
6 files changed
+284
-235
No files matched your search
@@ -1,71 +1,80 @@
|
||||
#ifndef MESSAGE_HPP
|
||||
#define MESSAGE_HPP
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace Plains {
|
||||
namespace Resolver {
|
||||
|
||||
using std::size_t;
|
||||
using std::unique_ptr;
|
||||
|
||||
class Message
|
||||
{
|
||||
/*
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ID |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
|QR| OpCode |AA|TC|RD|RA| Z | RCODE |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| QDCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ANCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| NSCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ARCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*/
|
||||
|
||||
public:
|
||||
struct RCode { enum FLAG { NO_ERR, FORMAT_ERR, SERVER_FAIL, NAME_ERR, NOT_IMPL, REFUSED, YX_DOM, YX_RR_SET, NX_RR_SET, NOT_AUTH, NOT_ZONE }; };
|
||||
struct OpCode { enum FLAG { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; };
|
||||
struct QR { enum FLAG { QUERY, RESPONSE }; };
|
||||
struct AA { enum FLAG { NON_AUTHORATATIVE, AUTHORATATIVE }; };
|
||||
struct TC { enum FLAG { NON_TRUNCATED, TRUNCATED }; };
|
||||
struct RD { enum FLAG { NOT_DESIRED, DESIRED }; };
|
||||
struct RA { enum FLAG { NOT_AVAILABLE, AVAILABLE }; };
|
||||
|
||||
struct Buffer {
|
||||
size_t size;
|
||||
void* data;
|
||||
};
|
||||
|
||||
Message();
|
||||
size_t size();
|
||||
Message(const Buffer& buffer);
|
||||
|
||||
public: //change to private after debugging
|
||||
class Header {
|
||||
public:
|
||||
/*
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ID |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
|QR| OpCode |AA|TC|RD|RA| Z | RCODE |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| QDCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ANCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| NSCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ARCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*/
|
||||
struct RCode { enum FLAG { NO_ERR, FORMAT_ERR, SERVER_FAIL, NAME_ERR, NOT_IMPL, REFUSED, YX_DOM, YX_RR_SET, NX_RR_SET, NOT_AUTH, NOT_ZONE }; };
|
||||
struct OpCode { enum FLAG { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; };
|
||||
struct QR { enum FLAG { QUERY, RESPONSE }; };
|
||||
struct AA { enum FLAG { NON_AUTHORATATIVE, AUTHORATATIVE }; };
|
||||
struct TC { enum FLAG { NON_TRUNCATED, TRUNCATED }; };
|
||||
struct RD { enum FLAG { NOT_DESIRED, DESIRED }; };
|
||||
struct RA { enum FLAG { NOT_AVAILABLE, AVAILABLE }; };
|
||||
unsigned id() const; // Identifyer
|
||||
unsigned rCode() const; // Response Code
|
||||
unsigned qdCount() const; // Question Count
|
||||
unsigned anCount() const; // Answer Record Count
|
||||
unsigned nsCount() const; // Authority Record Count
|
||||
unsigned arCount() const; // Additional Record Count
|
||||
unsigned opCode() const; // Operation Code
|
||||
bool qr() const; // Query/Respose Flag
|
||||
bool aa() const; // Authoratative Answer Flag
|
||||
bool tc() const; // Truncation Flag
|
||||
bool rd() const; // Recursion Desired Flag
|
||||
bool ra() const; // Recursion Available Flag
|
||||
unique_ptr<Buffer> encodeMessage() const; // Creates network byte-orderd message to be sent
|
||||
|
||||
unsigned id() const; // Identifyer
|
||||
unsigned rCode() const; // Response Code
|
||||
unsigned qdCount() const; // Question Count
|
||||
unsigned anCount() const; // Answer Record Count
|
||||
unsigned nsCount() const; // Authority Record Count
|
||||
unsigned arCount() const; // Additional Record Count
|
||||
unsigned opCode() const; // Operation Code
|
||||
bool qr() const; // Query/Respose Flag
|
||||
bool aa() const; // Authoratative Answer Flag
|
||||
bool tc() const; // Truncation Flag
|
||||
bool rd() const; // Recursion Desired Flag
|
||||
bool ra() const; // Recursion Available Flag
|
||||
|
||||
void id (unsigned value);
|
||||
void rCode (unsigned value);
|
||||
void qdCount(unsigned value);
|
||||
void anCount(unsigned value);
|
||||
void nsCount(unsigned value);
|
||||
void arCount(unsigned value);
|
||||
void opCode (unsigned value);
|
||||
void qr(QR::FLAG flag);
|
||||
void aa(AA::FLAG flag);
|
||||
void tc(TC::FLAG flag);
|
||||
void rd(RD::FLAG flag);
|
||||
void ra(RA::FLAG flag);
|
||||
void id (unsigned value);
|
||||
void rCode (unsigned value);
|
||||
void qdCount(unsigned value);
|
||||
void anCount(unsigned value);
|
||||
void nsCount(unsigned value);
|
||||
void arCount(unsigned value);
|
||||
void opCode (unsigned value);
|
||||
void qr(QR::FLAG flag);
|
||||
void aa(AA::FLAG flag);
|
||||
void tc(TC::FLAG flag);
|
||||
void rd(RD::FLAG flag);
|
||||
void ra(RA::FLAG flag);
|
||||
void decodeMessage(const Buffer& buffer);
|
||||
|
||||
private:
|
||||
struct Header {
|
||||
private:
|
||||
unsigned _id : 16; //Identifier: A 16-bit identification field generated by the device that creates the DNS query. It is copied by the server into the response, so it can be used by that device to match that query to the corresponding reply received from a DNS server. This is used in a manner similar to how the Identifier field is used in many of the ICMP message types.
|
||||
bool _qr : 1; //Query/Response Flag: Differentiates between queries and responses. Set to 0 when the query is generated; changed to 1 when that query is changed to a response by a replying server.
|
||||
@@ -80,13 +89,25 @@ class Message
|
||||
unsigned _anCount : 16; //Answer Record Count: Specifies the number of resource records in the Answer section of the message.
|
||||
unsigned _nsCount : 16; //Authority Record Count: Specifies the number of resource records in the Authority section of the message. (“NS” stands for “name server”, of course. J)
|
||||
unsigned _arCount : 16; //Additional Record Count: Specifies the number of resource records in the Additional section of the message.
|
||||
} header;
|
||||
};
|
||||
|
||||
struct Question {} question;
|
||||
struct Answer {} answer;
|
||||
struct Authority {} authority;
|
||||
struct Additional {} additional;
|
||||
unsigned _id;
|
||||
bool _qr;
|
||||
unsigned _opCode;
|
||||
bool _aa;
|
||||
bool _tc;
|
||||
bool _rd;
|
||||
bool _ra;
|
||||
unsigned _rCode;
|
||||
unsigned _qdCount;
|
||||
unsigned _anCount;
|
||||
unsigned _nsCount;
|
||||
unsigned _arCount;
|
||||
|
||||
vector<ResourceRecord> _question;
|
||||
vector<ResourceRecord> _answer;
|
||||
vector<ResourceRecord> _authority;
|
||||
vector<ResourceRecord> _additional;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user