summaryrefslogtreecommitdiff
path: root/lib/Socket.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Socket.cc')
-rw-r--r--lib/Socket.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Socket.cc b/lib/Socket.cc
index d3d7c19..f35bb72 100644
--- a/lib/Socket.cc
+++ b/lib/Socket.cc
@@ -122,3 +122,17 @@ Socket Socket::Accept(void) throw (GeneralException) {
return Socket(h);
}
}
+
+int Socket::GetPort() {
+ int r;
+ struct sockaddr_in localsocketaddr;
+ socklen_t locallen = sizeof(localsocketaddr);
+
+ if (getsockname(GetHandle(), (struct sockaddr *) &localsocketaddr, &locallen)) {
+ return -1;
+ }
+
+ r = ntohs(localsocketaddr.sin_port);
+
+ return r;
+}