This commit is contained in:
Suraxius committed 2021-01-24 12:39:56 +01:00
1 parent 07812d62cd
commit 8d3b6d7592
5 files changed
+60 -26

No files matched your search

+9
View File
@@ -106,6 +106,15 @@ Logger::Sink& Logger::Sink::operator<<(const char* msg) {
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const int msg) {
if ( level_ >= parent_.logLevel ) {
prefixLine();
*parent_.output << msg;
}
return *this;
}
Logger::Sink& Logger::Sink::operator<<(const long msg) {
if ( level_ >= parent_.logLevel ) {
prefixLine();
+1
View File
@@ -34,6 +34,7 @@ class Logger {
Sink& operator<<(const char character);
Sink& operator<<(const string& msg);
Sink& operator<<(const char* msg);
Sink& operator<<(const int msg);
Sink& operator<<(const long msg);
Sink& operator<<(const unsigned long msg);
};
Binary file not shown.
+28 -17
View File
@@ -17,8 +17,8 @@ using asio::ip::udp;
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
const char* dict = "0123456789ABCDEF";
char left = c & 0xF; //Mask upper 4 bits on the right
char right = c >> 4;
out[0] = dict[right];
out[1] = dict[left];
@@ -26,15 +26,25 @@ static char* byteToHex(char c) {
}
static char* intToHex(unsigned byteCount, int c) {
static char* out = new char[byteCount*3+1];
//static char* out = new char[byteCount*3+1];
static char* out = new char[32];
const char* byte = (char*)&c;
printf("%x\n", c);
printf("%x\n", byte[0] & 0xFF);
printf("%x\n", byte[1] & 0xFF);
out[byteCount*3] = 0x0; //Terminate string
out[4] = 0xE; //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] = ' ';
std::cout << "i(" << i << ") ";
//char byte = (c >> (i*8)) & 0xFF;
const char* nibble = byteToHex(byte[i]);
out[i*3] = nibble[0];
out[i*3+1] = nibble[1];
out[i*3+2] = ' ';
std::cout << "Char1(" << out[0] << ") Char2(" << out[1] << ") Char3(" << out[2] << ")" << std::endl;
}
return out;
}
@@ -43,14 +53,14 @@ Server::Server(Logger& logger, EventBus& eventBus)
: logger_(logger),
eventBus_(eventBus)
{
logger.debug << "Testing some stuff..." << Logger::commit;
logger.debug << "Message header overall size: " << sizeof(Message::Header) << Logger::commit;
// logger.debug << "Message::Header size:" << sizeof(Message::Header) << endl;
// logger.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
logger_.debug << "Testing some stuff..." << Logger::commit;
logger_.debug << "Message header overall size: " << sizeof(Message::Header) << Logger::commit;
// logger_.debug << "Message::Header size:" << sizeof(Message::Header) << endl;
// logger_.debug << "Message::QR:RESPONSE Enum:" << Message::QR::RESPONSE << endl;
std::fstream myfile;
std::streampos beg,end;
myfile.open ("/tmp/dnsmessage", std::ios::in | std::ios::binary);
myfile.open ("/tmp/packet.bin", std::ios::in | std::ios::binary);
myfile.seekg (0, std::ios::end);
end = myfile.tellg();
myfile.seekg (0, std::ios::beg);
@@ -58,10 +68,11 @@ Server::Server(Logger& logger, EventBus& eventBus)
const unsigned long size = end-beg;
Message::Header* header = new Message::Header;
myfile.read ((char*)header, sizeof(Message));
logger.debug << "size is: " << size << " bytes." << Logger::commit;
logger_.debug << "size is: " << size << " bytes." << Logger::commit;
logger.debug << "Header: " << Logger::commit <<
"ID: " << intToHex(2, header->id) <<
logger_.debug << "Header: " << Logger::commit;
//logger_.debug << "ID: " << 0x1ef8 <<
logger_.debug << "ID: " << intToHex(2, header->id) <<
" QR: " << byteToHex(header->qr) <<
" OPCode: " << byteToHex(header->opCode) << Logger::commit <<
"Authoritive Answer: " << byteToHex(header->aa) << Logger::commit <<
+22 -9
View File
@@ -7,28 +7,41 @@ namespace Resolver {
class Message
{
public:
//private:
//const enum id {};
struct Header {
/*
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 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 }; };
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.
unsigned int 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 int 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.
unsigned int 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.
unsigned int 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.
unsigned int 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.