Skip to content

Commit

Permalink
Merge pull request #27 from ahupowerdns/multi
Browse files Browse the repository at this point in the history
Multi
  • Loading branch information
ahupowerdns authored Oct 11, 2018
2 parents 9d8cf87 + bffb7eb commit 838d527
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tdns/dnsmessages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ bool DNSMessageReader::getRR(DNSSection& section, DNSName& name, DNSType& type,
{
if(payloadpos == payload.size())
return false;
if(rrpos < ntohs(dh.ancount))
section = DNSSection::Answer;
else if(rrpos < ntohs(dh.ancount) + ntohs(dh.nscount))
section = DNSSection::Authority;
else
section = DNSSection::Additional;
++rrpos;
name = getName();
type=(DNSType)getUInt16();
/* uint16_t lclass = */ getUInt16(); // class
Expand Down
1 change: 1 addition & 0 deletions tdns/dnsmessages.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public:
struct dnsheader dh=dnsheader{}; //!< the DNS header
std::vector<uint8_t> payload; //!< The payload
uint16_t payloadpos{0}; //!< Current position of processing
uint16_t rrpos{0}; //!< Used in getRR to set section correctly
uint16_t d_endofrecord;
//! are we at the end of a record?
bool eor() const { return payloadpos == d_endofrecord; }
Expand Down
13 changes: 11 additions & 2 deletions tdns/tdns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ std::unique_ptr<DNSNode> retrieveZone(const ComboAddress& remote, const DNSName&
int main(int argc, char** argv)
try
{
if(argc != 2) {
if(argc < 2) {
cerr<<"Syntax: tdns ipaddress:port"<<endl;
return(EXIT_FAILURE);
}
Expand All @@ -552,7 +552,6 @@ try

Socket udplistener(local.sin4.sin_family, SOCK_DGRAM);
SBind(udplistener, local);


Socket tcplistener(local.sin4.sin_family, SOCK_STREAM);
SSetsockopt(tcplistener, SOL_SOCKET, SO_REUSEPORT, 1);
Expand All @@ -566,6 +565,16 @@ try
cout<<"Listening on TCP & UDP on "<<local.toStringWithPort()<<endl;

thread udpServer(udpThread, local, &udplistener, &zones);

for(int n = 2; n < argc; ++n) {
ComboAddress local2(argv[n], 53);
auto udplistener2 = new Socket(local2.sin4.sin_family, SOCK_DGRAM);
SBind(*udplistener2, local2);
cout<<"Listening on UDP on "<<local2.toStringWithPort()<<endl;
thread udpServer2(udpThread, local2, udplistener2, &zones);
udpServer2.detach();
}

cout<<"Server is live"<<endl;
for(;;) {
ComboAddress remote(local); // this sets the family correctly
Expand Down

0 comments on commit 838d527

Please sign in to comment.