From 3877234037d1828056ad5b138c0533311d22f29e Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 23 Nov 2019 22:40:24 +0100 Subject: [PATCH] Using underscores as colon replacement --- server/src/handler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/handler.cpp b/server/src/handler.cpp index 5729f8c..28e51e0 100644 --- a/server/src/handler.cpp +++ b/server/src/handler.cpp @@ -80,16 +80,16 @@ void WebDNSHandler::handle_message(const std::shared_ptr& bind #define MAX_IPV6_ADDRESS_STR_LEN 39 //Address at least one char long! -bool parse_v6(uint8_t(result)[16], const std::string_view& address) { +bool parse_v6(uint8_t(result)[16], const std::string_view& address, char colon = ':') { uint16_t accumulator{0}; uint8_t colon_count{0}, pos{0}; memset(result, 0, 16); - // Step 1: look for position of ::, and count colons after it + // Step 1: look for position of ::, and count col ons after it for(uint8_t i = 1; i <= MAX_IPV6_ADDRESS_STR_LEN && address.length() > i; i++) { - if (address[i] == ':') { - if (address[i - 1] == ':') { + if (address[i] == colon) { + if (address[i - 1] == colon) { colon_count = 14; // Double colon! } else if (colon_count) { colon_count -= 2; // Count backwards the number of colons after the :: @@ -99,12 +99,12 @@ bool parse_v6(uint8_t(result)[16], const std::string_view& address) { // Step 2: convert from ascii to binary for(uint8_t i=0; i <= MAX_IPV6_ADDRESS_STR_LEN && pos < 16; i++) { - if (address[i] == ':' || address.length() == i) { + if (address[i] == colon || address.length() == i) { result[pos] = accumulator >> 8U; result[pos + 1] = accumulator; accumulator = 0; - if (colon_count && i && address[i - 1] == ':') { + if (colon_count && i && address[i - 1] == colon) { pos = colon_count; } else { pos += 2; @@ -165,7 +165,7 @@ void create_answer(DNSBuilder& response, const ClientAddress & client_address, c if(parts.size() != 3) return; in6_addr result{}; - if(!parse_v6(result.__in6_u.__u6_addr8, parts[0])) return; + if(!parse_v6(result.__in6_u.__u6_addr8, parts[0], '_')) return; log_dns()->info("[{}] Sending requested IPv6 ({}): {}", client_address.str, dn, net::to_string(result));