title: Unable to do AF_UNIX socket IPC in Android using NDK: Operation not permitted
body: <p>I am attempting to use unix-domain sockets and am developing under the NDK. I am routinely receiving <code>Operation not permitted</code> errors for various actions related to trivial <code>AF_UNIX</code>/<code>SOCK_DGRAM</code> type IPC. </p>
  
  <p>I am able to successfully <code>bind</code> both processes to a particular interface but am unable to either <code>connect</code> or <code>send</code>/<code>sendto</code> without getting the error mentioned above. The bound interfaces <em>do</em> appear on the file system if an appropriate <code>ls</code> is done in the specified directory. Also, each interface name is given explicit <code>other-read/write</code> access using <code>chmod</code> to prevent any permissions problems. </p>
  
  <p><strong>Process A (Consumer):</strong></p>
  
  <pre><code>struct sockaddr_un local_addr;
  int ctrl_fd;
  
  /* Clean the structure and copy over our observable address */
  bzero(&amp;local_addr, sizeof(struct sockaddr_un));
  strncpy(local_addr.sun_path, local_sock_name, sizeof(local_sock_name));
  local_addr.sun_family = AF_UNIX;
  
  ctrl_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
  
  bind(ctrl_fd, (struct sockaddr *) &amp;local_addr, sizeof(struct sockaddr_un));
  
  /* Associate with our path */
  connect(ctrl_fd, (struct sockaddr *) &amp;local_addr, sizeof(struct sockaddr_un));
  
  while(1){
      recvLen = recv(ctrl_fd, buf, sizeof(buf), 0);
      printf("Received: %s\n", buf);
  }
  </code></pre>
  
  <p><strong>Process B (Producer):</strong></p>
  
  <pre><code>int sock_fd;
  struct sockaddr_un dest_addr, local_addr;
  
  /* Get our socket handle */
  sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
  
  /* Define where we are to connect */
  bzero(&amp;dest_addr, sizeof(struct sockaddr_un));
  strncpy(dest_addr.sun_path, dest_name, sizeof(dest_name));
  dest_addr.sun_family = AF_UNIX;
  
  /* Define who we are */
  bzero(&amp;local_addr, sizeof(struct sockaddr_un));
  strncpy(local_addr.sun_path, local_name, sizeof(local_name));
  local_addr.sun_family = AF_UNIX;
  
  /* Make a name for ourself */
  bind(sock_fd, (struct sockaddr *) &amp;local_addr, sizeof(struct sockaddr_un));
  
  /* Associate fd with remote address */
  connect(sock_fd, (struct sockaddr *) &amp;dest_addr, sizeof(struct sockaddr_un));
  
  while(1){
      sleep(10);
      send(sock_fd, "test", sizeof("test"), 0);
  }
  </code></pre>
  
  <p>However, I have managed only to be denied by <code>Operation not permitted</code> on both <code>connect</code> and <code>send</code>. Additionally, I tried removing the <code>connect</code> call entirely and simply using <code>sendto</code>, but I get the same error. </p>
  
  <p><strong>Note</strong>: I have removed any error printing from the snippet for brevity. In the actual code I am determining these errors by checking the return values of each sys-call and doing a <code>strerror(errno)</code> to get the respective error message. </p>