diff --git a/includes/client.hpp b/includes/client.hpp index 3c01942..fc66948 100644 --- a/includes/client.hpp +++ b/includes/client.hpp @@ -15,7 +15,7 @@ public: ~Client(); /* Normal constructor that calls the parent constructor to set the given values */ - Client(int ip_ver, char protocol, const char* address, int port) : Sock(ip_ver, protocol, address, port) {} + Client(char protocol, const char* address, int port) : Sock(protocol, address, port) {} void create_socket() override; diff --git a/includes/server.hpp b/includes/server.hpp index 1d22e5c..e8a2196 100644 --- a/includes/server.hpp +++ b/includes/server.hpp @@ -15,7 +15,7 @@ public: /* Constructors */ Server() {} - Server(int ip_ver, char protocol, const char* address, int port) : Sock(ip_ver, protocol, address, port) {} + Server(char protocol, const char* address, int port) : Sock(protocol, address, port) {} /* Destructor */ ~Server(); diff --git a/includes/sock.hpp b/includes/sock.hpp index b73eca3..1d2e7b7 100644 --- a/includes/sock.hpp +++ b/includes/sock.hpp @@ -38,7 +38,7 @@ public: virtual ~Sock(); /* Regular constructor - defined in sock.cpp */ - Sock(int ip_ver, char protocol, const char* address, int port); + Sock(char protocol, const char* address, int port); /* Method to send data in 'to_send' through the 'other_socket' socket */ void sendAll(std::string to_send); diff --git a/sock.cpp b/sock.cpp index b4842c9..91f366b 100644 --- a/sock.cpp +++ b/sock.cpp @@ -18,11 +18,12 @@ Sock::~Sock() {} /* Constructor - This function initializes the object attributes with the given -parameters. It throws an exception if an IPv4 address was given, but the type -given is IPv6 (or the other way around). */ +parameters. The address version (IPv4 or IPv6) is determined based on the given address. */ -Sock::Sock(int ip_ver, char protocol, const char* address, int port) { +Sock::Sock(char protocol, const char* address, int port) { /* Error checking */ + this->ip_ver = check_ip_ver(address); + if (ip_ver != 4 && ip_ver != 6) { throw std::invalid_argument("Invalid IP address type"); } @@ -37,11 +38,6 @@ Sock::Sock(int ip_ver, char protocol, const char* address, int port) { this->protocol = protocol; this->port = port; this->address = std::string(address); - - /* Check to see if the given IP address matches the given ip_ver */ - if ((check_ip_ver(address) != 6 && ip_ver == 6) || (check_ip_ver(address) != 4 && ip_ver == 4)) { - throw std::invalid_argument("Invalid IP address for given type."); - } } /* This method sends the given data, through the 'other_sockt' variable.. Client