wip
This commit is contained in:
1 parent
064ac24c10
commit
05325b0ca7
5 files changed
+69
-10
No files matched your search
@@ -98,6 +98,14 @@ Logger::Sink& Logger::Sink::operator<<(const char* msg) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::Sink& Logger::Sink::operator<<(const long msg) {
|
||||||
|
if ( level >= parent.logLevel ) {
|
||||||
|
prefixLine();
|
||||||
|
*parent.output << msg;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Logger::Sink& Logger::Sink::operator<<(const unsigned long msg) {
|
Logger::Sink& Logger::Sink::operator<<(const unsigned long msg) {
|
||||||
if ( level >= parent.logLevel ) {
|
if ( level >= parent.logLevel ) {
|
||||||
prefixLine();
|
prefixLine();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class Logger {
|
|||||||
Sink& operator<<(const char character);
|
Sink& operator<<(const char character);
|
||||||
Sink& operator<<(const string& msg);
|
Sink& operator<<(const string& msg);
|
||||||
Sink& operator<<(const char* msg);
|
Sink& operator<<(const char* msg);
|
||||||
|
Sink& operator<<(const long msg);
|
||||||
Sink& operator<<(const unsigned long msg);
|
Sink& operator<<(const unsigned long msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ int main(int args, char **argv) {
|
|||||||
|
|
||||||
//Record testrec = ARecord();
|
//Record testrec = ARecord();
|
||||||
|
|
||||||
logger.info << "Testing overloading!" << " with chaining!" << Logger::commit;
|
|
||||||
logger.debug.ln ("PlaiNS successfully started.");
|
logger.debug.ln ("PlaiNS successfully started.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+54
-4
@@ -1,19 +1,69 @@
|
|||||||
#include "Server.hpp"
|
#include "Server.hpp"
|
||||||
|
#include <fstream>
|
||||||
//Testing:
|
//Testing:
|
||||||
#include "Message.hpp"
|
#include "Message.hpp"
|
||||||
|
|
||||||
namespace Plains {
|
namespace Plains {
|
||||||
namespace Resolver {
|
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) {
|
Server::Server(Logger& logger, EventBus& eventBus) : logger(logger), eventBus(eventBus) {
|
||||||
logger.debug << "Testing some stuff..." << Logger::commit;
|
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::Header size:" << sizeof(Message::Header) << endl;
|
||||||
// logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
|
// logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
|
||||||
|
|
||||||
//test:
|
std::fstream myfile;
|
||||||
eventBus.test();
|
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() {
|
Server::~Server() {
|
||||||
|
|||||||
@@ -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 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 int arCount : 16; //Additional Record Count: Specifies the number of resource records in the Additional section of the message.
|
||||||
};
|
} header;
|
||||||
|
|
||||||
struct Question {};
|
struct Question {} question;
|
||||||
struct Answer {};
|
struct Answer {} answer;
|
||||||
struct Authority {};
|
struct Authority {} authority;
|
||||||
struct Additional {};
|
struct Additional {} additional;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user