diff --git a/sock.cpp b/sock.cpp index 07b01a3..f081fd5 100644 --- a/sock.cpp +++ b/sock.cpp @@ -37,6 +37,13 @@ Sock::Sock(char protocol, const char* address, int port) { this->address = std::string(address); } +/* This method returns whether or not the socket is connected to a remote address */ +bool Sock::get_remote_address() { + struct sockaddr_storage addr; + socklen_t len = sizeof(addr); + return getpeername(this->sock_fd, (struct sockaddr*)&addr, &len) == 0; +} + /* This method sends the given data, through the 'other_sockt' variable.. Client and server classes extend this method, by setting this variable to different values. This function needs more testing for TCP, as it focuses on UDP right now. */