套接字(AF_INET,SOCK_DGRAM,IPPROTO_ICMP)失败,errno = 13(权限被拒绝)
问题描述:
在adb shell中运行,并由NDK编译。套接字(AF_INET,SOCK_DGRAM,IPPROTO_ICMP)失败,errno = 13(权限被拒绝)
我的代码:
#include <sys/socket.h>
#include <errno.h>
#include <linux/netlink.h>
#include <linux/in.h>
#include <string.h>
#include <stdio.h>
int main()
{
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
printf("sock = %d and errno = %d\n", sock, errno);
return 0;
}
输出:
[email protected]:/data/local/tmp $ ./poc
sock = -1 and errno = 13
有谁知道为什么吗?
答
见https://developer.android.com/guide/topics/manifest/uses-permission-element.html
它看起来像你需要添加: -
<uses-permission android:name="android.permission.INTERNET" />
可能重复的Using Socket() in Android NDK
如果你的目标的Android 7.0,它可能是值得考虑的权限更改为https://developer.android.com/about/versions/nougat/android-7.0-changes.html,但这取决于您的targetSdkVersion是否大于
你有没有把你的SELinux设置为'enforced'或'permissive'模式?另外,运行你的程序后('dmesg')什么是内核输出? –
vbox86p:/数据/本地的/ tmp#getenforce 残疾人 – jptang
的dmesg: [8.208501] qtaguid:ctrl_counterset(S 1 10023):从PID = 466 TGID = 279 UID PRIV不足= 1000 [9.362826] INIT: sys_prop:permission denied uid:1003 name:service.bootanim.exit [10.959880] eth0:没有IPv6路由器存在 [20.643991] eth1:没有IPv6路由器存在 – jptang