Skip to content
Snippets Groups Projects
Commit dad7e99d authored by dnsadmin's avatar dnsadmin
Browse files

Adatbázisból nem támogatott típus kivétel (#11)

parent a649d363
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
* The format should be treated on the side of the caller. * The format should be treated on the side of the caller.
* @param new_rdata Bytes to the rdata to store * @param new_rdata Bytes to the rdata to store
* @param new_rdata_len Number of bytes in new_rdata * @param new_rdata_len Number of bytes in new_rdata
* @throws server_error when unsupported DNS type is set
*/ */
void set_rdata(const char *new_rdatas); void set_rdata(const char *new_rdatas);
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
* Adds error parts to the DNS message. * Adds error parts to the DNS message.
* This means a pseudo record to the additional section. * This means a pseudo record to the additional section.
* After this, the message should be sent. * After this, the message should be sent.
* Sets FORMERR flag in the additional section.
* @param msg The textual message to add to the additional section. * @param msg The textual message to add to the additional section.
*/ */
void set_error(const char *msg); void set_error(const char *msg);
......
#include "../include/dns_answer.h" #include "../include/dns_answer.h"
#include "../include/dns_types.h" #include "../include/dns_types.h"
#include "../include/exceptions/server_error.h"
#include <string.h> #include <string.h>
dns_answer::dns_answer(const dns_answer& other) : dns_question(other), ttl(other.ttl), rd_length(other.rd_length) { dns_answer::dns_answer(const dns_answer& other) : dns_question(other), ttl(other.ttl), rd_length(other.rd_length) {
...@@ -39,8 +40,7 @@ void dns_answer::set_rdata(const char* new_rdata) { ...@@ -39,8 +40,7 @@ void dns_answer::set_rdata(const char* new_rdata) {
treat_TXT_rdata(new_rdata); treat_TXT_rdata(new_rdata);
break; break;
default: default:
// May throw some exception... throw server_error("This record type is not supported.");
return;
} }
} }
......
...@@ -19,9 +19,9 @@ void dns_message_em::set_error(const char* msg) { ...@@ -19,9 +19,9 @@ void dns_message_em::set_error(const char* msg) {
err_report.set_name("error.dns"); err_report.set_name("error.dns");
err_report.set_type(DNS_TYPE_TXT); err_report.set_type(DNS_TYPE_TXT);
err_report.set_ttl(300); err_report.set_ttl(300);
err_report.set_rdata(msg); err_report.set_rdata(msg); // No exception may occure (TXT must be supported)
add_additional(err_report); add_additional(err_report);
// header.set_flag(DNS_FLAG_RCODE_FORMERR); // In case it has not been set yet. header.set_flag(DNS_FLAG_RCODE_FORMERR); // In case it has not been set yet.
} }
void dns_message_em::add_answer(const dns_answer& new_answer) { void dns_message_em::add_answer(const dns_answer& new_answer) {
......
...@@ -119,6 +119,10 @@ void dns_server::serve_one_request() { ...@@ -119,6 +119,10 @@ void dns_server::serve_one_request() {
{ {
log_on_demand(LOG_ERR, ex.what()); log_on_demand(LOG_ERR, ex.what());
} }
catch(server_error err)
{
resp.set_error(err.what());
}
//--- //---
this->socket.sendto_wp(resp, 0, (sockaddr*) &sender, slen); this->socket.sendto_wp(resp, 0, (sockaddr*) &sender, slen);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment