diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-06-12 23:49:37 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-06-12 23:49:37 +0200 |
commit | 177c770bbb4c75b42688d5c5e7627c2fef8500e5 (patch) | |
tree | b16068146e6f1ba0afa1b94d438c5c405b623696 /src | |
parent | fb86311df4e1db902cbb6f527ad6c038543973a8 (diff) | |
download | mad-177c770bbb4c75b42688d5c5e7627c2fef8500e5.tar mad-177c770bbb4c75b42688d5c5e7627c2fef8500e5.zip |
Peer-Addresse nach Verbindungsaufbau updaten
Diffstat (limited to 'src')
-rw-r--r-- | src/Net/IPAddress.h | 8 | ||||
-rw-r--r-- | src/Net/ServerConnection.cpp | 7 |
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); |