summary refs log tree commit diff stats
path: root/lib/pure/net.nim
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-09-15 10:37:58 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2015-09-15 10:37:58 +0100
commitd24eaf084b4be17e43f262d4127a91993ae6f7cd (patch)
tree50c27ed7aef949b3e089423874a5bb2a122696b1 /lib/pure/net.nim
parentac16b151bad9d4d4bae6e6ac35c52b2c5173ec7a (diff)
parent4da5e474148db9298ec0d730046544278d7e6827 (diff)
downloadNim-d24eaf084b4be17e43f262d4127a91993ae6f7cd.tar.gz
Merge branch 'rbehrends-socket-address' into devel
Diffstat (limited to 'lib/pure/net.nim')
-rw-r--r--lib/pure/net.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim
index 141543c70..0ce5b4d25 100644
--- a/lib/pure/net.nim
+++ b/lib/pure/net.nim
@@ -533,6 +533,18 @@ proc getSockOpt*(socket: Socket, opt: SOBool, level = SOL_SOCKET): bool {.
   var res = getSockOptInt(socket.fd, cint(level), toCInt(opt))
   result = res != 0
 
+proc getLocalAddr*(socket: Socket): (string, Port) =
+  ## Get the socket's local address and port number.
+  ##
+  ## This is high-level interface for `getsockname`:idx:.
+  getLocalAddr(socket.fd, socket.domain)
+
+proc getPeerAddr*(socket: Socket): (string, Port) =
+  ## Get the socket's peer address and port number.
+  ##
+  ## This is high-level interface for `getpeername`:idx:.
+  getPeerAddr(socket.fd, socket.domain)
+
 proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {.
   tags: [WriteIOEffect].} =
   ## Sets option ``opt`` to a boolean value specified by ``value``.