Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi #27

Merged
merged 4 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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