0

I have made an executable binary built through android ndk. I put the binary in /data/local/tmp. In the binary I try to bind a socket which I later on want to listen through my android app. I have got root permissions still the bind shows 30 as error which means read only file system. Can anyone tell me what else do I need to do bind a socket?

My code in brief:

int serv_sock = -1, len;
struct sockaddr_un serv_soc_addr;

if ((serv_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    printf(   "socket error:%d\n", errno);
    return -1; // Terminatie DR
}

bzero(&serv_soc_addr, sizeof(serv_soc_addr));
serv_soc_addr.sun_family = AF_UNIX;
strcpy(serv_soc_addr.sun_path, "iptable_socket");
unlink(serv_soc_addr.sun_path);
len = strlen(serv_soc_addr.sun_path) + sizeof(serv_soc_addr.sun_family);

if (0 != bind(serv_sock, (struct sockaddr*) &serv_soc_addr, len)) {
    printf(  "bind error:%d\n", errno);
    close(serv_sock);
    return -1; //Terminate DR
}

root@android:/ # /data/local/tmp/hello-jni

bind error:30

tariq zafar
  • 659
  • 7
  • 24

1 Answers1

0

I was able to solve this one myself. Probably someone else looking for this might find helpful.

  1. I changed the type of socket from Abstract type to FileSystem type.
  2. I put the unlink statement at the end of the function after the accept system call breaks rather than just after strcpy as above.
  3. Lastly I ran chmod on my binary.

Any other pointers would be helpful. Thanks.

tariq zafar
  • 659
  • 7
  • 24