Removed ip_ver parameter

I removed this because I realized I could just check the IP version inside
the constructor. The Sock constructor now checks the address passed to it.
Like before, if the address is neither v4 nor v6, an exception is thrown.
Since the Server and Client constructors call the Sock constructor, no change
was required in these files, except passing the right number of parameters.
master
Aadhavan Srinivasan 10 months ago
parent 764f343f5d
commit 0058e7e411

@ -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;

@ -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();

@ -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);

@ -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

Loading…
Cancel
Save