summary refs log tree commit diff stats
path: root/lib/pure/net.nim
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2018-09-15 17:54:58 +0200
committerLemonBoy <thatlemon@gmail.com>2018-09-15 20:43:08 +0200
commita2a06d43f239933f0961ee903a167ae149b02606 (patch)
tree881311df2d02748137be2392cd75add61a8a1d8c /lib/pure/net.nim
parent0c04b80651ff591beadb873c8814168e66e6b722 (diff)
downloadNim-a2a06d43f239933f0961ee903a167ae149b02606.tar.gz
Fix connectUnix/bindUnix with abstract socket paths
The only way to make this work for both abstract and non-abstract
sockets is to send the kernel an incomplete structure.

Reported by Epictek on the forum.
Diffstat (limited to 'lib/pure/net.nim')
-rw-r--r--lib/pure/net.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim
index a60137dab..67cb95e2f 100644
--- a/lib/pure/net.nim
+++ b/lib/pure/net.nim
@@ -964,7 +964,7 @@ when defined(posix) or defined(nimdoc):
     when not defined(nimdoc):
       var socketAddr = makeUnixAddr(path)
       if socket.fd.connect(cast[ptr SockAddr](addr socketAddr),
-                        sizeof(socketAddr).Socklen) != 0'i32:
+                           (sizeof(socketAddr.sun_family) + path.len).Socklen) != 0'i32:
         raiseOSError(osLastError())
 
   proc bindUnix*(socket: Socket, path: string) =
@@ -973,7 +973,7 @@ when defined(posix) or defined(nimdoc):
     when not defined(nimdoc):
       var socketAddr = makeUnixAddr(path)
       if socket.fd.bindAddr(cast[ptr SockAddr](addr socketAddr),
-                            sizeof(socketAddr).Socklen) != 0'i32:
+                            (sizeof(socketAddr.sun_family) + path.len).Socklen) != 0'i32:
         raiseOSError(osLastError())
 
 when defined(ssl):