socket(AF_INET,SOCK_DGRAM,0)失败返回-1

时间:2016-07-12 12:03:43

标签: android c sockets

在android M中,我编译了一个守护进程和驱动程序通信,程序必须使用

struct sockaddr_in addr;
char buffer[1024];
mcSocket_t *mcs = (mcSocket_t *)data;

/* initialize socket */
mcs->sock = socket(PF_INET, SOCK_DGRAM, 0);
if(mcs->sock < 0)
{
   //LOGE("%s: error on socket(): %d", __func__, mcs->sock);
    LOGE("%s: error on socket(): %d = %s", __func__, errno, strerror(errno));
   goto exitCommandThread;
}
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(mcs->port);
addr.sin_addr.s_addr = INADDR_ANY;

/* bind to address and port */
if (0 != bind(mcs->sock, (struct sockaddr*)&addr, sizeof(addr)))
{
   LOGE("%s: error on bind(): %d = %s", __func__, errno, strerror(errno));
   running = 0;
}

但是我执行了 / system / bin / daemon ,socket(PF_INET,SOCK_DGRAM,0);总是返回mcs-&gt; sock = -1,在socket()上打印:错误:13 =权限被拒绝

0 个答案:

没有答案