diff --git a/Jupiter/SecureSocket.cpp b/Jupiter/SecureSocket.cpp index 11e9e2f..38d3891 100644 --- a/Jupiter/SecureSocket.cpp +++ b/Jupiter/SecureSocket.cpp @@ -67,7 +67,7 @@ Jupiter::SecureSocket::~SecureSocket() if (Jupiter::SecureSocket::SSLdata_ != nullptr) delete Jupiter::SecureSocket::SSLdata_; } -Jupiter::SecureSocket *Jupiter::SecureSocket::acceptConnection() +Jupiter::SecureSocket *Jupiter::SecureSocket::accept() { int tSock = SSL_accept(Jupiter::SecureSocket::SSLdata_->handle); if (tSock > 0) diff --git a/Jupiter/SecureSocket.h b/Jupiter/SecureSocket.h index 79f6a59..1b70828 100644 --- a/Jupiter/SecureSocket.h +++ b/Jupiter/SecureSocket.h @@ -96,7 +96,7 @@ namespace Jupiter * @param Address for client to bind to. * @return True on success, false otherwise. */ - virtual bool connectToHost(const char *hostname, unsigned short iPort, const char *clientAddress = nullptr, unsigned short clientPort = 0); + virtual bool connectToHost(const char *hostname, unsigned short iPort, const char *clientAddress = nullptr, unsigned short clientPort = 0) override; /** * @brief Interface to provide simple binding to ports. @@ -106,19 +106,19 @@ namespace Jupiter * @param andListen True if listen() should be called, false otherwise. * @return True on success, false otherwise. */ - virtual bool bindToPort(const char *hostname, unsigned short iPort, bool andListen = true); + virtual bool bindToPort(const char *hostname, unsigned short iPort, bool andListen = true) override; /** * @brief Accepts an incoming connection for the port bound to. * * @return A valid SecureSocket on success, nullptr otherwise. */ - virtual SecureSocket *acceptConnection(); + virtual SecureSocket *accept() override; /** * @brief Closes the socket. */ - virtual void closeSocket(); + virtual void closeSocket() override; /** * @brief Writes new data from the socket to the buffer, without removing it from the socket queue. @@ -127,7 +127,7 @@ namespace Jupiter * @return Number of bytes received on success, less than or equal to 0 otherwise. * Note: Refer to SSL_read() for detailed return values. */ - virtual int peek(); + virtual int peek() override; /** * @brief Writes new data from the socket to the buffer. @@ -136,7 +136,7 @@ namespace Jupiter * @return Number of bytes received on success, less than or equal to 0 otherwise. * Note: Refer to SSL_read() for detailed return values. */ - virtual int recv(); + virtual int recv() override; /** * @brief Sends data across the socket. @@ -146,7 +146,7 @@ namespace Jupiter * @return Number of bytes sent on success, less than or equal to 0 otherwise. * Note: Refer to SSL_write() for detailed return values. */ - virtual int send(const char *data, size_t datalen); + virtual int send(const char *data, size_t datalen) override; /** * @brief Initializes SSL on the socket. diff --git a/Jupiter/Socket.cpp b/Jupiter/Socket.cpp index b58440c..fca30e3 100644 --- a/Jupiter/Socket.cpp +++ b/Jupiter/Socket.cpp @@ -352,15 +352,28 @@ Jupiter::StringS Jupiter::Socket::ntop(void *ip, size_t size) } } -Jupiter::Socket *Jupiter::Socket::acceptConnection() +Jupiter::Socket *Jupiter::Socket::accept() { - SOCKET tSock = accept(Socket::data_->rawSock, 0, 0); + sockaddr addr; + int size = sizeof(addr); + SOCKET tSock = ::accept(Socket::data_->rawSock, &addr, &size); if (tSock != INVALID_SOCKET) { + char resolved[NI_MAXHOST]; + getnameinfo(&addr, size, resolved, NI_MAXHOST, 0, 0, NI_NUMERICHOST); Socket *r = new Socket(Jupiter::Socket::data_->bufflen); r->data_->rawSock = tSock; r->data_->sockType = Jupiter::Socket::data_->sockType; r->data_->sockProto = Jupiter::Socket::data_->sockProto; + r->data_->host.set(resolved); + char *end = resolved + r->data_->host.size(); + while (end != resolved) + { + if (*--end == ':') + break; + r->data_->port *= 10; + r->data_->port += static_cast(Jupiter_getBase(*end, 10)); + } return r; } return nullptr; diff --git a/Jupiter/Socket.h b/Jupiter/Socket.h index 7fcf528..bcd40ed 100644 --- a/Jupiter/Socket.h +++ b/Jupiter/Socket.h @@ -243,7 +243,7 @@ namespace Jupiter * * @return A valid Socket on success, nullptr otherwise. */ - virtual Socket *acceptConnection(); + virtual Socket *accept(); /** * @brief Sets the timeout for recv() in milliseconds. diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 00849a1..5fc6d9b 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ