diff --git a/llarp/config.cpp b/llarp/config.cpp index 5d6ea1434..82ed7986b 100644 --- a/llarp/config.cpp +++ b/llarp/config.cpp @@ -162,7 +162,7 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath) f << "upstream=" << DEFAULT_RESOLVER_EU << std::endl; f << "# opennic au resolver" << std::endl; f << "upstream=" << DEFAULT_RESOLVER_AU << std::endl; - f << "bind=127.3.2.1:53" << std::endl; + f << "bind=127.0.0.1:53" << std::endl; f << std::endl << std::endl; f << "# network database settings block " << std::endl; diff --git a/llarp/dns.cpp b/llarp/dns.cpp index 91a96d7ef..98c08ad2e 100644 --- a/llarp/dns.cpp +++ b/llarp/dns.cpp @@ -230,12 +230,6 @@ extern "C" decode_answer(const char *const buffer, uint32_t *pos) { dns_msg_answer *answer = new dns_msg_answer; - // skip for now until we can handle compressed labels - /* - std::string aName = getDNSstring((char *)buffer); - buffer += aName.size() + 1; - */ - /* llarp_buffer_t bob; bob.base = (unsigned char *)buffer; @@ -243,14 +237,10 @@ extern "C" llarp::DumpBuffer(bob); */ - // hexDump(buffer, 10); - const char *moveable = buffer; // llarp::LogDebug("Advancing to pos ", std::to_string(*pos)); moveable += (*pos); // advance to position - // hexDumpAt(buffer, (*pos) - 2, 12); - // hexDump(moveable, 12); if(*moveable == '\xc0') { // hexDump(moveable, 12); @@ -273,7 +263,14 @@ extern "C" else { // get DNSString? - llarp::LogWarn("Need to parse string"); + llarp::LogWarn("Need to parse string, implement me"); + /* + uint32_t readAt32 = *pos; + answer->name = getDNSstring(buffer, &readAt32); + llarp::LogInfo("Parsed string ", answer->name, " read ", std::to_string(readAt32)); + moveable += readAt32; (*pos) += readAt32; + */ + //moveable++; (*pos)++; } /* hexDump(moveable, 10); @@ -369,10 +366,12 @@ extern "C" { std::string revname = getDNSstring(buffer, pos); llarp::LogInfo("revDNSname: ", revname); + //answer->rData = new uint8_t[answer->rdLen + 1]; answer->rData.resize(answer->rdLen); memcpy(answer->rData.data(), revname.c_str(), answer->rdLen); + //answer->rData = (uint8_t *)strdup(revname.c_str()); // safer? nope moveable += answer->rdLen; - (*pos) += answer->rdLen; // advance the length + //(*pos) += answer->rdLen; // advance the length } break; case 15: diff --git a/llarp/dnsc.cpp b/llarp/dnsc.cpp index a29853044..2990a529b 100644 --- a/llarp/dnsc.cpp +++ b/llarp/dnsc.cpp @@ -218,17 +218,6 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, llarp::LogDebug("msg nsc ", msg->nsCount); llarp::LogDebug("msg arc ", msg->arCount); - // we may need to parse question first - - /* - dns_msg_question *question = decode_question((const char *)castBuf); - llarp::LogInfo("que name ", question->name); - castBuf += question->name.length() + 8; - - dns_msg_answer *answer = decode_answer((const char *)castBuf); - castBuf += answer->name.length() + 4 + 4 + 4 + answer->rdLen; - */ - // FIXME: only handling one atm uint32_t pos = 12; // just set after header dns_msg_question *question = nullptr; @@ -241,6 +230,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, // castBuf += question->name.length() + 1 + 4; // castBuf += 2; // skip answer label } + llarp::LogInfo("Question ", std::to_string(question->type), " ", question->name); // FIXME: only handling one atm std::vector< dns_msg_answer * > answers; @@ -306,8 +296,15 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, // pos = 0; // reset pos answer = decode_answer(castBufc, &pos); // answers.push_back(answer); - llarp::LogDebug("Read an authority"); + llarp::LogDebug("Read an authority for ", + request->question.name, " at ", std::to_string(pos)); // castBuf += answer->name.length() + 4 + 4 + 4 + answer->rdLen; + if(pos > sz) + { + llarp::LogWarn("Would read past end of dns packet. for ", + request->question.name); + break; + } } /* @@ -396,6 +393,14 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, int ip = 0; + // if no answer, just bail now + if (!answer) + { + request->found = false; + request->resolved(request); + return; + } + /* search for and print IPv4 addresses */ // if(dnsQuery->reqType == 0x01) /* @@ -452,7 +457,7 @@ generic_handle_dnsc_recvfrom(dnsc_answer_request *request, return; } } - else if(request->question.type == 12) + else if(answer->type == 12) { llarp::LogDebug("Resolving PTR"); request->found = true;