This commit is contained in:
Sven Luethi committed 2021-04-28 00:23:43 +02:00
1 parent 29b4df31fd
commit af592f2082
3 files changed
+49 -38

No files matched your search

+5 -5
View File
@@ -24,11 +24,11 @@ void Message::Header::anCount(unsigned value) { _anCount = htons(value); }
void Message::Header::nsCount(unsigned value) { _nsCount = htons(value); } void Message::Header::nsCount(unsigned value) { _nsCount = htons(value); }
void Message::Header::arCount(unsigned value) { _arCount = htons(value); } void Message::Header::arCount(unsigned value) { _arCount = htons(value); }
void Message::Header::opCode (unsigned value) { _opCode = htons(value); } void Message::Header::opCode (unsigned value) { _opCode = htons(value); }
void Message::Header::rd (bool flag) { _rd = flag; } void Message::Header::rd (RD::FLAG flag) { _rd = flag; }
void Message::Header::aa (bool flag) { _aa = flag; } void Message::Header::aa (AA::FLAG flag) { _aa = flag; }
void Message::Header::tc (bool flag) { _tc = flag; } void Message::Header::tc (TC::FLAG flag) { _tc = flag; }
void Message::Header::ra (bool flag) { _ra = flag; } void Message::Header::ra (RA::FLAG flag) { _ra = flag; }
void Message::Header::qr (QR::ENUM flag) { _qr = flag; } void Message::Header::qr (QR::FLAG flag) { _qr = flag; }
size_t Message::size() { return 12; } size_t Message::size() { return 12; }
+17 -1
View File
@@ -126,10 +126,26 @@ void Server::run() {
std::cout << std::endl << std::endl; std::cout << std::endl << std::endl;
*/ */
Message* message = (Message*) &buffer; Message* message = (Message*) &buffer;
_logger.warn << "ID: " << message->header.id() << Logger::commit;
//Spit out some header values for debugging.
_logger.warn << "ID: " << message->header.id();
_logger.warn << " QR: " << message->header.qr();
_logger.warn << " OPCode: " << message->header.opCode();
_logger.warn << " AA: " << message->header.aa();
_logger.warn << " TC: " << message->header.tc();
_logger.warn << " RD: " << message->header.rd();
_logger.warn << " RA: " << message->header.ra();
_logger.warn << " RCode: " << message->header.rCode();
_logger.warn << " QDCount: " << message->header.qdCount();
_logger.warn << " ANCount: " << message->header.anCount();
_logger.warn << " NSCount: " << message->header.nsCount();
_logger.warn << " ARCount: " << message->header.arCount();
_logger.warn << Logger::commit;
// Change message to response type and send back for testing // Change message to response type and send back for testing
message->header.qr(Message::Header::QR::RESPONSE); message->header.qr(Message::Header::QR::RESPONSE);
//message->header.aa(Message::Header::AA::AUTHORATATIVE);
//message->header.ra(Message::Header::RA::AVAILABLE);
//if ( sendto(udpServerSocket, msg, strlen(msg), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) { //if ( sendto(udpServerSocket, msg, strlen(msg), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) {
if ( sendto(udpServerSocket, message, message->size(), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) { if ( sendto(udpServerSocket, message, message->size(), 0, (struct sockaddr*)&clientAddress, clientAddressLength) < 0 ) {
+27 -32
View File
@@ -32,22 +32,26 @@ class Message
| ARCOUNT | | ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/ */
struct QR { enum ENUM { QUERY, RESPONSE }; }; 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 ENUM { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; }; struct OpCode { enum FLAG { QUERY, IQUERY, STATUS, reserved, NOTIFY, UPDATE }; };
struct RCode { enum 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 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; unsigned id() const; // Identifyer
unsigned rCode() const; unsigned rCode() const; // Response Code
unsigned qdCount() const; unsigned qdCount() const; // Question Count
unsigned anCount() const; unsigned anCount() const; // Answer Record Count
unsigned nsCount() const; unsigned nsCount() const; // Authority Record Count
unsigned arCount() const; unsigned arCount() const; // Additional Record Count
unsigned opCode() const; unsigned opCode() const; // Operation Code
bool rd() const; bool qr() const; // Query/Respose Flag
bool aa() const; bool aa() const; // Authoratative Answer Flag
bool tc() const; bool tc() const; // Truncation Flag
bool ra() const; bool rd() const; // Recursion Desired Flag
bool qr() const; bool ra() const; // Recursion Available Flag
void id (unsigned value); void id (unsigned value);
void rCode (unsigned value); void rCode (unsigned value);
@@ -56,37 +60,25 @@ class Message
void nsCount(unsigned value); void nsCount(unsigned value);
void arCount(unsigned value); void arCount(unsigned value);
void opCode (unsigned value); void opCode (unsigned value);
void rd(bool flag); void qr(QR::FLAG flag);
void aa(bool flag); void aa(AA::FLAG flag);
void tc(bool flag); void tc(TC::FLAG flag);
void ra(bool flag); void rd(RD::FLAG flag);
void qr(QR::ENUM flag); void ra(RA::FLAG flag);
private: 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. 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 _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 _z : 3; //Zero: Three reserved bits set to zero. unsigned _z : 3; //Zero: Three reserved bits set to zero.
unsigned _rCode : 4; unsigned _rCode : 4;
unsigned _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 _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 _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 _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; } header;
@@ -98,6 +90,9 @@ class Message
}; };
}} }}
#endif #endif