summary refs log tree commit diff stats
path: root/lib/deprecated/pure/sockets.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-03-29 15:30:44 +0200
committerAraq <rumpf_a@web.de>2016-03-29 15:31:10 +0200
commitdb2b2156581ffaaa63e7ff9c0a07ced540006956 (patch)
tree341535aa355ef422ee886f7b14fda6fbfeae0523 /lib/deprecated/pure/sockets.nim
parent8bf14b12a963980e71ad46e16a8a2e35c9465b8c (diff)
parentb4f1eef3a3b0ff56d0a68c15c43ffecb7778e939 (diff)
downloadNim-db2b2156581ffaaa63e7ff9c0a07ced540006956.tar.gz
resolved merge conflicts
Diffstat (limited to 'lib/deprecated/pure/sockets.nim')
-rw-r--r--lib/deprecated/pure/sockets.nim16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/deprecated/pure/sockets.nim b/lib/deprecated/pure/sockets.nim
index f7d0950d8..20e6d9364 100644
--- a/lib/deprecated/pure/sockets.nim
+++ b/lib/deprecated/pure/sockets.nim
@@ -206,6 +206,18 @@ proc htons*(x: int16): int16 =
   ## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
   result = sockets.ntohs(x)
 
+template ntohl(x: uint32): expr =
+  cast[uint32](sockets.ntohl(cast[int32](x)))
+
+template ntohs(x: uint16): expr =
+  cast[uint16](sockets.ntohs(cast[int16](x)))
+
+template htonl(x: uint32): expr =
+  sockets.ntohl(x)
+
+template htons(x: uint16): expr =
+  sockets.ntohs(x)
+
 when defined(Posix):
   proc toInt(domain: Domain): cint =
     case domain
@@ -451,7 +463,7 @@ proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
       name.sin_family = int16(ord(AF_INET))
     else:
       name.sin_family = posix.AF_INET
-    name.sin_port = sockets.htons(int16(port))
+    name.sin_port = sockets.htons(uint16(port))
     name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
     if bindSocket(socket.fd, cast[ptr SockAddr](addr(name)),
                   sizeof(name).SockLen) < 0'i32:
@@ -834,7 +846,7 @@ proc connect*(socket: Socket, address: string, port = Port(0),
   when false:
     var s: TSockAddrIn
     s.sin_addr.s_addr = inet_addr(address)
-    s.sin_port = sockets.htons(int16(port))
+    s.sin_port = sockets.htons(uint16(port))
     when defined(windows):
       s.sin_family = toU16(ord(af))
     else: