diff options
author | pixel <pixel> | 2007-06-17 11:14:17 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-06-17 11:14:17 +0000 |
commit | e049a4f28b69f8c2912cb7dcba8ac4901638653f (patch) | |
tree | e522d73d2737a79b4de01603639f9d5d1993d55a /lib | |
parent | 44f709cefdebe26a1e0084debd0652a44ae5b1da (diff) |
Adding some useful socket functions.
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); |