title: LD_PRELOAD socket calls cause Segmentation fault at bind() syscall
body: <p>I'm trying to LD_PRELOAD (<code>LD_PRELOAD=./my_lib.so ./a.out</code>) an executable with simple <code>AF_INET</code> socket calls. 
  I want to catch the call, and proceed with <code>AF_VSOCK</code> address family instead of <code>AF_INET</code>.
  <code>socket()</code>, <code>connect()</code> works well. The problem is when I call <code>bind()</code> I get a segmentation fault
  (<code>segfault at 60 ip 00007f4f4b2ea59a sp 00007fff9eb53dd8 error 4 in libc-2.13.so[7f4f4b261000+184000]</code>)</p>
  
  <p>lib.so:</p>
  
  <pre><code>typedef int (*bind_orig_ftype)(int sockfd, const struct sockaddr *addr,socklen_t addrlen);
  
  int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
  {
      bind_orig_ftype bind_original;
      struct sockaddr_vm vmaddr;
  
      bind_original= (bind_orig_ftype) dlsym(RTLD_NEXT,"bind");
  
      vmaddr.svm_family = AF_VSOCK;
      vmaddr.svm_cid = 42;
      vmaddr.svm_port = 1234;
      printf("Intercepted\n");
      return (bind_original(sockfd,(struct sockaddr *) &amp;vmaddr,sizeof(struct sockaddr)));
  }
  </code></pre>
  
  <p>I got "Intercepted" printed and then the <code>segfault</code>. I'm thinking the problem is about <code>struct sockaddr_vm</code> passing it to bind_original, but when I call bind at <code>AF_VSOCK</code>, without LD_PRELOADing everything works well.</p>
  
  <p>Any ideas? Or how to check where the sefault occurs?</p>