From 177c770bbb4c75b42688d5c5e7627c2fef8500e5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 12 Jun 2008 23:49:37 +0200 Subject: Peer-Addresse nach Verbindungsaufbau updaten --- src/Net/IPAddress.h | 8 ++++++++ src/Net/ServerConnection.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') 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(&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); -- cgit v1.2.3