summaryrefslogtreecommitdiffstats
path: root/src/Net
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net')
-rw-r--r--src/Net/IPAddress.h8
-rw-r--r--src/Net/ServerConnection.cpp7
2 files changed, 14 insertions, 1 deletions
diff --git a/src/Net/IPAddress.h b/src/Net/IPAddress.h
index e892323..c1709d5 100644
--- a/src/Net/IPAddress.h
+++ b/src/Net/IPAddress.h
@@ -41,6 +41,14 @@ class IPAddress {
throw InvalidAddressException(address);
}
+ IPAddress(const struct sockaddr_in &address) : sa(address) {
+ p = ntohs(sa.sin_port);
+
+ char buf[INET_ADDRSTRLEN];
+ inet_ntop(AF_INET, &address, buf, sizeof(buf));
+ addr = buf;
+ }
+
const std::string& getAddress() const {return addr;}
unsigned short getPort() const {return p;}
diff --git a/src/Net/ServerConnection.cpp b/src/Net/ServerConnection.cpp
index 1e0959d..7c9f9b8 100644
--- a/src/Net/ServerConnection.cpp
+++ b/src/Net/ServerConnection.cpp
@@ -53,7 +53,10 @@ void ServerConnection::listen(const IPAddress &address) throw(ConnectionExceptio
throw ConnectionException("listen()", std::strerror(errno));
}
- sock = accept(listen_sock, NULL, NULL);
+ struct sockaddr_in sa;
+ socklen_t addrlen = sizeof(sa);
+
+ sock = accept(listen_sock, reinterpret_cast<struct sockaddr*>(&sa), &addrlen);
if(sock < 0) {
close(listen_sock);
delete peer;
@@ -63,6 +66,8 @@ void ServerConnection::listen(const IPAddress &address) throw(ConnectionExceptio
close(listen_sock);
+ *peer = IPAddress(address);
+
connected = true;
gnutls_init(&session, GNUTLS_SERVER);