title: Can not connect to Linux "abstract" unix socket
body: <p>I'm trying to use UNIX sockets for inter-thread communication. The program is only intended to run on Linux. To avoid creating the socket files, I wanted to use "abstract" sockets, as documented in unix(7).</p>
  
  <p>However, I don't seem to be able to connect to these sockets. Everything works if I'm using "pathname" sockets, though.</p>
  
  <p>Here is the code (I haven't quoted any error handling, but it's done):
  thread#1:</p>
  
  <pre><code>int log_socket = socket(AF_LOCAL, SOCK_STREAM, 0);
  struct sockaddr_un logaddr;
  socklen_t sun_len = sizeof(struct sockaddr_un);
  logaddr.sun_family = AF_UNIX;
  logaddr.sun_path[0] = 0;
  strcpy(logaddr.sun_path+1, "futurama");
  bind(log_socket, &amp;logaddr, sun_len);
  listen(log_socket, 5);
  accept(log_socket, &amp;logaddr, &amp;sun_len);
  ... // send - receive
  </code></pre>
  
  <p>thread#2:</p>
  
  <pre><code>struct sockaddr_un tolog;
  int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
  tolog.sun_family = AF_UNIX;
  tolog.sun_path[0] = 0;
  strcpy(tolog.sun_path+1, "futurama");
  connect(sock, (struct sockaddr*)&amp;tolog, sizeof(struct sockaddr_un));
  </code></pre>
  
  <p>If all I do in the above code, is change the sun_path to not have leading \0, things work perfect.</p>
  
  <p>strace output:</p>
  
  <pre><code>t1: socket(PF_FILE, SOCK_STREAM, 0)         = 0
  t1: bind(0, {sa_family=AF_FILE, path=@"futurama"}, 110)
  t1: listen(0, 5)
  t2: socket(PF_FILE, SOCK_STREAM, 0) = 1
  t2: connect(1, {sa_family=AF_FILE, path=@"futurama"}, 110 &lt;unfinished ...&gt;
  t2: &lt;... connect resumed&gt; )     = -1 ECONNREFUSED (Connection refused)
  t1: accept(0,  &lt;unfinished ...&gt;
  </code></pre>
  
  <p>I know that the connect comes before accept, that's not an issue (I tried making sure that accept() is called before connect(), same result. Also, things are fine if the socket is "pathname" anyway).</p>