[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

PrzemeK report at bugs.python.org
Tue Nov 3 06:15:22 EST 2015


New submission from PrzemeK:

Case: http://stackoverflow.com/questions/33465094/connection-refused-when-using-abstract-namespace-unix-sockets

The code that does not work (python3 example):
...
sock_path = b"/var/tmp/sock.tmp"
server.bind(b"\0" + sock_path)
...
and strace shows:
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 20) = -1 ECONNREFUSED (Connection refused)

For C-written client strace shows:
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = 0

The code that actually works (python3 example):
...
sun_path_len = 108
sock_path = b"/var/tmp/sock.tmp"
server.bind(b"\0" + sock_path + (b"\0" * (sun_path_len - len(sock_path) - 1)))
...
and strace shows:
bind(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = 0
110 it's the correst size of a struct.

There's no hint at https://docs.python.org/3/library/socket.html#socket-families for that.

Test files (servers and clients): https://gist.github.com/soutys/ffbe2e76a86835a9cc6b

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25541>
_______________________________________


More information about the Python-bugs-list mailing list