Started working on client-side decoding of IPv6 code

master
Aadhavan Srinivasan 10 months ago
parent 00b83e6de2
commit 2c7d1d0b43

@ -103,10 +103,13 @@ namespace connect_code {
std::string addr_expanded = expand_ip6_addr(address);
std::string addr_coded = "";
std::vector<std::string> 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<std::string> decode(std::string connect_code) {
//<AIRPLANE_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;
}
//</AIRPLANE_CODE>
if (connect_code.find("_") == std::string::npos) {
throw std::invalid_argument("Invalid code entered.");
}

Loading…
Cancel
Save