Added new exception for invalid IP, used it if IP address is neither v4 nor v6

master
Aadhavan Srinivasan 8 months ago
parent 48739f6026
commit 912435bfa3

@ -5,5 +5,6 @@ static const int EXCEPT_CONNREFUSED = 10;
static const int EXCEPT_TOOFEWARGS = 15;
static const int EXCEPT_INVALIDARGS = 20;
static const int EXCEPT_ADDRNOTAVAIL = 25;
static const int EXCEPT_INVALIDIP = 30;
#endif

@ -96,7 +96,7 @@ Mode check_server_client(int argc, char** argv, Server* server, Client* client)
/* Check if IP is valid */
if (check_ip_ver(addr.data()) < 0) {
throw EXCEPT_INVALIDARGS;
throw EXCEPT_INVALIDIP;
}
std::string code = connect_code::encode(addr, std::to_string(port));
@ -134,7 +134,7 @@ int main(int argc, char** argv) {
return -1;
}
if (e == EXCEPT_INVALIDARGS) {
std::cout << "Invalid argument.." << std::endl;
std::cout << "Invalid argument." << std::endl;
return -2;
}
if (e == EXCEPT_CONNREFUSED) {
@ -145,9 +145,13 @@ int main(int argc, char** argv) {
std:: cout << "Unable to use requested address for server." << std::endl;
return -4;
}
if (e == EXCEPT_INVALIDIP) {
std::cout << "Invalid IP address provided." << std::endl;
return -5;
}
} catch(std::invalid_argument& inv) {
std::cout << inv.what() << std::endl;
return -5;
return -6;
}
/* Initialize window and other variables */

Loading…
Cancel
Save