diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Socket.cc | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/Socket.cc b/lib/Socket.cc index 890457f..7c0dba1 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Socket.cc,v 1.24 2007-05-30 11:57:10 pixel Exp $ */ +/* $Id: Socket.cc,v 1.25 2007-06-17 11:14:18 pixel Exp $ */ #ifdef _WIN32 #include <winsock2.h> @@ -212,6 +212,48 @@ int Socket::GetPort() { return r; } +Uint32 Socket::GetAddr() { + uint32_t r; + struct sockaddr_in localsocketaddr; + socklen_t locallen = sizeof(localsocketaddr); + + if (getsockname(GetHandle(), (struct sockaddr *) &localsocketaddr, &locallen)) { + return -1; + } + + r = ntohl(localsocketaddr.sin_addr.s_addr); + + return r; +} + +int Socket::GetDistantPort() { + int r; + struct sockaddr_in distantsockaddr; + socklen_t distantlen = sizeof(distantsockaddr); + + if (getpeername(GetHandle(), (struct sockaddr *) &distantsockaddr, &distantlen)) { + return -1; + } + + r = ntohs(distantsockaddr.sin_port); + + return r; +} + +Uint32 Socket::GetDistantAddr() { + uint32_t r; + struct sockaddr_in distantsockaddr; + socklen_t distantlen = sizeof(distantsockaddr); + + if (getpeername(GetHandle(), (struct sockaddr *) &distantsockaddr, &distantlen)) { + return -1; + } + + r = ntohl(distantsockaddr.sin_addr.s_addr); + + return r; +} + bool Socket::FinalizeConnect() { int r; socklen_t l = sizeof(r); |