This commit is contained in:
Suraxius committed 2021-01-12 00:11:47 +01:00
1 parent 064ac24c10
commit 05325b0ca7
5 files changed
+69 -10

No files matched your search

+54 -4
View File
@@ -1,19 +1,69 @@
#include "Server.hpp"
#include <fstream>
//Testing:
#include "Message.hpp"
namespace Plains {
namespace Resolver {
static char* byteToHex(char c) {
static char* out = new char[3];
out[2] = 0x0; //Terminate string
char* dict = (char*) "0123456789ABCDEF";
char left = c & 0xF; //Mask upper 4 bits on the right
char right = c >> 4;
out[0] = dict[right];
out[1] = dict[left];
return out;
}
static char* intToHex(unsigned byteCount, int c) {
static char* out = new char[byteCount*3+1];
out[byteCount*3] = 0x0; //Terminate string
out[4] = 0xE; //Terminate string
for (unsigned i = 0; i < byteCount; i++) {
char byte = (c >> i*8) & 0xFF;
char* nibble = byteToHex(byte);
out[i*3] = nibble[0];
out[i*3+1] = nibble[1];
out[i*3+2] = ' ';
}
return out;
}
Server::Server(Logger& logger, EventBus& eventBus) : logger(logger), eventBus(eventBus) {
logger.debug << "Testing some stuff..." << Logger::commit;
logger.debug << "Message class overall size:" << sizeof(Message) << Logger::commit;
logger.debug << "Message class overall size: " << sizeof(Message) << Logger::commit;
// logger.debug << "Message::Header size:" << sizeof(Message::Header) << endl;
// logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
//test:
eventBus.test();
std::fstream myfile;
std::streampos beg,end;
myfile.open ("/tmp/dnsmessage", std::ios::in | std::ios::binary);
myfile.seekg (0, std::ios::end);
end = myfile.tellg();
myfile.seekg (0, std::ios::beg);
beg = myfile.tellg();
const unsigned long size = end-beg;
Message* message = new Message();
myfile.read ((char*)message, sizeof(Message));
logger.debug << "size is: " << size << " bytes." << Logger::commit;
logger.debug << "Header: " << Logger::commit <<
"ID: " << intToHex(2, message->header.id) <<
" QR: " << byteToHex(message->header.qr) <<
" OPCode: " << byteToHex(message->header.opCode) << Logger::commit <<
"Authoritive Answer: " << byteToHex(message->header.aa) << Logger::commit <<
"Truncation Flag: " << byteToHex(message->header.tc) << Logger::commit <<
"Recursion Desired: " << byteToHex(message->header.rd) << Logger::commit <<
"Recursion Available: " << byteToHex(message->header.ra) << Logger::commit <<
"RCode: " << byteToHex(message->header.rCode) << Logger::commit <<
"Question Count: " << intToHex(2, message->header.qdCount) << Logger::commit <<
"Answer Record Count: " << intToHex(2, message->header.anCount) << Logger::commit <<
"Authority Record Count: " << intToHex(2, message->header.nsCount) << Logger::commit <<
"Additional Record Count: " << intToHex(2, message->header.arCount) << Logger::commit;
myfile.close();
}
Server::~Server() {
+6 -5
View File
@@ -40,14 +40,15 @@ class 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 int arCount : 16; //Additional Record Count: Specifies the number of resource records in the Additional section of the message.
};
} header;
struct Question {};
struct Answer {};
struct Authority {};
struct Additional {};
struct Question {} question;
struct Answer {} answer;
struct Authority {} authority;
struct Additional {} additional;
};
}}
#endif