diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps index 52b9d23..3cc6b5c 100644 Binary files a/cmake-build-debug/.ninja_deps and b/cmake-build-debug/.ninja_deps differ diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log index e45900d..f3bca87 100644 --- a/cmake-build-debug/.ninja_log +++ b/cmake-build-debug/.ninja_log @@ -25,3 +25,9 @@ 7588 7791 1698262928938405252 insane_dns ff5ae500893d0be1 5 7595 1698262972765775585 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421 7595 7803 1698262972985772451 insane_dns ff5ae500893d0be1 +3 2885 1698265110010893560 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421 +2885 2976 1698265110106892250 insane_dns ff5ae500893d0be1 +2 2934 1698265309664228253 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421 +2935 3019 1698265309752227101 insane_dns ff5ae500893d0be1 +2 3015 1698266342759371787 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421 +3015 3112 1698266342859370576 insane_dns ff5ae500893d0be1 diff --git a/cmake-build-debug/CMakeFiles/insane_dns.dir/src/main.cpp.o b/cmake-build-debug/CMakeFiles/insane_dns.dir/src/main.cpp.o index 132cf67..3a3555d 100644 Binary files a/cmake-build-debug/CMakeFiles/insane_dns.dir/src/main.cpp.o and b/cmake-build-debug/CMakeFiles/insane_dns.dir/src/main.cpp.o differ diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index ac2aa6f..f3d7b36 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Oct 25 15:42 EDT +Start testing: Oct 25 16:39 EDT ---------------------------------------------------------- -End testing: Oct 25 15:42 EDT +End testing: Oct 25 16:39 EDT diff --git a/cmake-build-debug/insane_dns b/cmake-build-debug/insane_dns index 48ee1b4..0ceb3a0 100755 Binary files a/cmake-build-debug/insane_dns and b/cmake-build-debug/insane_dns differ diff --git a/src/ip.h b/src/ip.h index 040fa41..1c0f18c 100644 --- a/src/ip.h +++ b/src/ip.h @@ -21,7 +21,10 @@ struct IPAddress auto data = blt::string::split(str, '.'); BLT_ASSERT(data.size() == 4); for (size_t i = 0; i < data.size(); i++) - data[i] = static_cast(std::stoul(data[i])); + { + octets[i] = static_cast(std::stoul(data[i])); + BLT_TRACE("%d", octets[i]); + } } constexpr IPAddress(unsigned char oct[4]) diff --git a/src/main.cpp b/src/main.cpp index 30128fb..f253453 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ * | CONFIG | * ---------------------------- */ -// should we strictly match results? ie block *.wikipedia.org or just wikipedia.org? +// should we strictly match results? ie block *wikipedia.org* or just wikipedia.org? static constexpr bool STRICT_MATCHING = false; // true -> only match A records ; false -> match any named record (A, AAAA, CNAME) static constexpr bool STRICT_FILTERING = false; @@ -170,6 +170,11 @@ class answer BLT_TRACE("%d, %d, %d, %d, %d", NAME, TYPE, CLASS, TTL, RDLENGTH); } + [[nodiscard]] uint16_t type() const + { + return TYPE; + } + void substitute(const IPAddress& addr) { BLT_ASSERT(RDLENGTH == 4); @@ -235,9 +240,6 @@ class send_buffer } else if constexpr (std::is_same_v) { static_assert("No"); -// std::memcpy(&internal_data[write_index], &t[0], t.length()); -// write_index += t.length(); -// write('\0'); } else if constexpr (std::is_same_v) { write(t.NAME); @@ -291,6 +293,19 @@ class send_buffer } }; +bool shouldReplace(const answer& a) +{ + return a.type() == 1; +} + +void process_answers(std::vector& answers) +{ + for (auto& a : answers) + { + if (shouldReplace(a)) + a.substitute(REPLACEMENT_IP()); + } +} int main() { @@ -336,8 +351,14 @@ int main() } BLT_INFO("DOMAIN: %s", q().c_str()); - for (auto& a : answers) - a.substitute(REPLACEMENT_IP()); + if (STRICT_MATCHING && DISALLOWED_DOMAINS.contains(q())) + process_answers(answers); + else if (!STRICT_MATCHING) + { + for (const auto& v : DISALLOWED_DOMAINS) + if (blt::string::contains(q(), v)) + process_answers(answers); + } send_buffer send; send.write(mod_recv_buf.data(), 12);