Overhauls Resolver Message class structure
This commit is contained in:
1 parent
4089e7a3cc
commit
95c9fbd176
4 files changed
+62
-39
No files matched your search
+3
-2
@@ -74,8 +74,9 @@ int main(int args, char **argv) {
|
|||||||
//Record testrec = ARecord();
|
//Record testrec = ARecord();
|
||||||
// End of Testcode
|
// End of Testcode
|
||||||
|
|
||||||
eventBus.run();
|
|
||||||
logger.info.ln ("Plains successfully started.");
|
logger.info.ln ("Plains successfully started.");
|
||||||
|
//shutdown();
|
||||||
|
eventBus.run();
|
||||||
}
|
}
|
||||||
catch (Exception& e) {
|
catch (Exception& e) {
|
||||||
logger.fatal << "Uncaught Exception: " << e.what() << Logger::commit;
|
logger.fatal << "Uncaught Exception: " << e.what() << Logger::commit;
|
||||||
@@ -110,7 +111,7 @@ void signalHandler( int signalNumber ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void shutdown() {
|
void shutdown() {
|
||||||
globalLogger->warn << "Shutting down Plains..." << Logger::commit;
|
globalLogger->info << "Shutting down Plains..." << Logger::commit;
|
||||||
globalResolver->~Server();
|
globalResolver->~Server();
|
||||||
globalUIServer->~Server();
|
globalUIServer->~Server();
|
||||||
globalEventBus->~EventBus();
|
globalEventBus->~EventBus();
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "Message.hpp"
|
#include "Message.hpp"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
namespace Plains {
|
namespace Plains {
|
||||||
namespace Resolver {
|
namespace Resolver {
|
||||||
|
|
||||||
|
unsigned Message::Header::getID() const {
|
||||||
|
return ntohs(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
//Testing:
|
//Testing:
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
@@ -30,7 +29,7 @@ Server::Server(Logger& logger, EventBus& eventBus)
|
|||||||
_logger.debug.ln ("Starting Resolver...");
|
_logger.debug.ln ("Starting Resolver...");
|
||||||
|
|
||||||
_logger.warn << "Testing some stuff..." << Logger::commit;
|
_logger.warn << "Testing some stuff..." << Logger::commit;
|
||||||
_logger.warn << "Message header overall size: " << sizeof(Message::Header) << Logger::commit;
|
_logger.warn << "Message::Header class overall size: " << sizeof(Message::Header) << Logger::commit;
|
||||||
//_logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
|
//_logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@@ -99,7 +98,7 @@ void Server::run() {
|
|||||||
clientAddressLength = sizeof(clientAddress);
|
clientAddressLength = sizeof(clientAddress);
|
||||||
|
|
||||||
// Create receive buffer
|
// Create receive buffer
|
||||||
char buffer[65508] = { 0 }; // (2**16 = 65,536 − 8 byte UDP header − 20 byte IP header)
|
unsigned char buffer[65508] = { 0 }; // (2**16 = 65,536 − 8 byte UDP header − 20 byte IP header)
|
||||||
|
|
||||||
// Create new UDP Socket
|
// Create new UDP Socket
|
||||||
if ((udpServerSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
if ((udpServerSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||||
@@ -114,18 +113,19 @@ void Server::run() {
|
|||||||
while(!_stop) {
|
while(!_stop) {
|
||||||
udpReadStatus = recvfrom(udpServerSocket, buffer, sizeof(buffer), 0, (struct sockaddr*)&clientAddress, &clientAddressLength);
|
udpReadStatus = recvfrom(udpServerSocket, buffer, sizeof(buffer), 0, (struct sockaddr*)&clientAddress, &clientAddressLength);
|
||||||
|
|
||||||
if (udpServerSocket < 0) {
|
if (udpServerSocket < 0) {
|
||||||
close(udpServerSocket);
|
close(udpServerSocket);
|
||||||
_logger.warn.ln("reading error...");
|
_logger.warn.ln("reading error...");
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::cout.write(buffer, udpReadStatus);
|
/*
|
||||||
//std::cout << "size: " << udpReadStatus << std::endl;
|
|
||||||
for(int i=0; i<udpReadStatus; ++i) {
|
for(int i=0; i<udpReadStatus; ++i) {
|
||||||
//std::cout << std::hex << (char)buffer[i];
|
//std::cout << std::hex << (char)buffer[i];
|
||||||
std::cout << std::setw(2) << static_cast<unsigned>(buffer[i]) << " ";
|
std::cout << std::setw(2) << static_cast<unsigned>(buffer[i]) << " ";
|
||||||
}
|
}
|
||||||
std::cout << std::endl << std::endl;
|
std::cout << std::endl << std::endl;
|
||||||
|
*/
|
||||||
|
Message* message = (Message*) &buffer;
|
||||||
|
|
||||||
if ( sendto(udpServerSocket, msg, strlen(msg), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) {
|
if ( sendto(udpServerSocket, msg, strlen(msg), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) {
|
||||||
close(udpServerSocket);
|
close(udpServerSocket);
|
||||||
|
|||||||
@@ -7,59 +7,77 @@ namespace Resolver {
|
|||||||
class Message
|
class Message
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Header {
|
Message();
|
||||||
/*
|
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
public: //change to private after debugging
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
class Header {
|
||||||
| ID |
|
public:
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
/*
|
||||||
|QR| OpCode |AA|TC|RD|RA| Z | RCODE |
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
| QDCOUNT |
|
| ID |
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
| ANCOUNT |
|
|QR| OpCode |AA|TC|RD|RA| Z | RCODE |
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
| NSCOUNT |
|
| QDCOUNT |
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
| ARCOUNT |
|
| ANCOUNT |
|
||||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
*/
|
| NSCOUNT |
|
||||||
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
|
| ARCOUNT |
|
||||||
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||||
|
*/
|
||||||
struct QR { enum { QUERY, RESPONSE }; };
|
struct QR { enum { QUERY, RESPONSE }; };
|
||||||
struct OpCode { enum { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; };
|
struct OpCode { enum { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; };
|
||||||
struct RCode { enum { NO_ERR, FORMAT_ERR, SERVER_FAIL, NAME_ERR, NOT_IMPL, REFUSED, YX_DOM, YX_RR_SET, NX_RR_SET, NOT_AUTH, NOT_ZONE }; };
|
struct RCode { enum { NO_ERR, FORMAT_ERR, SERVER_FAIL, NAME_ERR, NOT_IMPL, REFUSED, YX_DOM, YX_RR_SET, NX_RR_SET, NOT_AUTH, NOT_ZONE }; };
|
||||||
|
|
||||||
|
unsigned getID() const;
|
||||||
|
unsigned getRCode() const;
|
||||||
|
unsigned getQDCount() const;
|
||||||
|
unsigned getANCount() const;
|
||||||
|
unsigned getNSCount() const;
|
||||||
|
unsigned getARCount() const;
|
||||||
|
unsigned getOpCode() const;
|
||||||
|
bool getRD() const;
|
||||||
|
bool getAA() const;
|
||||||
|
bool getTC() const;
|
||||||
|
bool getRA() const;
|
||||||
|
bool getQR() const;
|
||||||
|
|
||||||
unsigned int 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.
|
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.
|
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.
|
||||||
|
|
||||||
unsigned int opCode : 4;
|
unsigned opCode : 4;
|
||||||
|
|
||||||
bool aa : 1; //Authoritative Answer Flag: This bit is set to 1 in a response to indicate that the server that created the response is authoritative for the zone in which the domain name specified in the Question section is located. If it is 0, the response is non-authoritative.
|
bool aa : 1; //Authoritative Answer Flag: This bit is set to 1 in a response to indicate that the server that created the response is authoritative for the zone in which the domain name specified in the Question section is located. If it is 0, the response is non-authoritative.
|
||||||
|
|
||||||
bool tc : 1; //Truncation Flag: When set to 1, indicates that the message was truncated due to its length being longer than the maximum permitted for the type of transport mechanism used. TCP doesn't have a length limit for messages, while UDP messages are limited to 512 bytes, so this bit being sent usually is an indication that the message was sent using UDP and was too long to fit. The client may need to establish a TCP session to get the full message. On the other hand, if the portion truncated was part of the Additional section, it may choose not to bother.
|
bool tc : 1; //Truncation Flag: When set to 1, indicates that the message was truncated due to its length being longer than the maximum permitted for the type of transport mechanism used. TCP doesn't have a length limit for messages, while UDP messages are limited to 512 bytes, so this bit being sent usually is an indication that the message was sent using UDP and was too long to fit. The client may need to establish a TCP session to get the full message. On the other hand, if the portion truncated was part of the Additional section, it may choose not to bother.
|
||||||
|
|
||||||
bool rd : 1; //Recursion Desired: When set in a query, requests that the server receiving the query attempt to answer the query recursively, if the server supports recursive resolution. The value of this bit is not changed in the response.
|
bool rd : 1; //Recursion Desired: When set in a query, requests that the server receiving the query attempt to answer the query recursively, if the server supports recursive resolution. The value of this bit is not changed in the response.
|
||||||
|
|
||||||
bool ra : 1; //Recursion Available: Set to 1 or cleared to 0 in a response to indicate whether the server creating the response supports recursive queries. This can then be noted by the device that sent the query for future use.
|
bool ra : 1; //Recursion Available: Set to 1 or cleared to 0 in a response to indicate whether the server creating the response supports recursive queries. This can then be noted by the device that sent the query for future use.
|
||||||
|
|
||||||
unsigned int z : 3; //Zero: Three reserved bits set to zero.
|
unsigned z : 3; //Zero: Three reserved bits set to zero.
|
||||||
|
|
||||||
unsigned int rCode : 4;
|
unsigned rCode : 4;
|
||||||
|
|
||||||
unsigned int qdCount : 16; //Question Count: Specifies the number of questions in the Question section of the message.
|
unsigned qdCount : 16; //Question Count: Specifies the number of questions in the Question section of the message.
|
||||||
|
|
||||||
unsigned int anCount : 16; //Answer Record Count: Specifies the number of resource records in the Answer section of the message.
|
unsigned anCount : 16; //Answer Record Count: Specifies the number of resource records in the Answer section of the message.
|
||||||
|
|
||||||
unsigned int 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 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 int arCount : 16; //Additional Record Count: Specifies the number of resource records in the Additional section of the message.
|
unsigned arCount : 16; //Additional Record Count: Specifies the number of resource records in the Additional section of the message.
|
||||||
};
|
} header;
|
||||||
|
|
||||||
struct Question {} question;
|
struct Question {} question;
|
||||||
struct Answer {} answer;
|
struct Answer {} answer;
|
||||||
struct Authority {} authority;
|
struct Authority {} authority;
|
||||||
struct Additional {} additional;
|
struct Additional {} additional;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user