From 2c7d1d0b4318dedde8a8adc6f4e7bf1730890d26 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 9 Mar 2024 21:34:47 -0500 Subject: [PATCH] Started working on client-side decoding of IPv6 code --- connect_code.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/connect_code.cpp b/connect_code.cpp index 24d221e..67c6292 100644 --- a/connect_code.cpp +++ b/connect_code.cpp @@ -103,10 +103,13 @@ namespace connect_code { std::string addr_expanded = expand_ip6_addr(address); std::string addr_coded = ""; std::vector addr_tokenized = tokenize_str(addr_expanded, ":"); - for (int i = 0; i < addr_tokenized.size(); i++ ) { + + for (int i = 0; i < addr_tokenized.size()-1; i++ ) { addr_coded += base_convert(addr_tokenized[i], 16, 32); addr_coded += "-"; } + addr_coded += base_convert(addr_tokenized[addr_tokenized.size()-1], 16, 32); // I put this outside the loop, because I don't want a hyphen after it + /* TODO - Check if the IP address is actually converted properly, and test if the server socket is created correctly. Also do the same for client side, and check client-server connection. */ @@ -124,6 +127,15 @@ namespace connect_code { } std::vector decode(std::string connect_code) { + // + int ip_ver = 0; + if (connect_code.find("-") == connect_code.npos) { + ip_ver = 6; // If the string contains hyphens, it must be an IPv6 address encoding. + } else { + ip_ver = 4; + } + + // if (connect_code.find("_") == std::string::npos) { throw std::invalid_argument("Invalid code entered."); }