网络链路实现为Android NDK [英] Netlink implementation for the Android NDK
问题描述
我有类似的任务要求为的此链接。。被动监测的Android插座。一种方法是解析的/ proc /净/ {TCP,UDP,...}表。但是,我们必须继续不断地阅读继续监测;这是没有效率的方法。因为这将是一个移动装置的应用程序,它会因为它需要的CPU时间上监视保持为时间间隔(例如1秒)吃起来电池
I have a requirement for similar task as mentioned in this link.. Passive monitoring of sockets in Android. One way is parsing the /proc/net/{tcp,udp,...} tables. But we have to keep on reading continuously for keep on monitoring; which is not efficient way. As it will be a mobile device app, it will eat up the battery as it requires CPU Time for keep on monitoring for time interval (say 1 sec).
不过,我要寻找一个基于事件的方法。当我用Google搜索差不多,我NETLINK结束了监测插座。但我观察到的Android NDK没有为支撑
But, I am looking for an event based approach. As I googled about the same, I ended with NETLINK for monitoring the sockets. But I observe that Android NDK doesn't have support for the
#include <linux/sock_diag.h>
#include <linux/inet_diag.h>
#include <linux/unix_diag.h>
#include <linux/packet_diag.h>
#include <linux/netlink_diag.h>
在是否使用Android的NETLINK监测INET套接字人试过?如果是的话请您分享的信息。
Does anyone tried using NETLINK in Android for monitoring the INET sockets? If so please share the information.
感谢。
更新:
我试图复制粘贴在JNI文件夹中的上述文件,并使用NDK的构建建。建筑是成功的,也是在运行时没有崩溃。但是,套接字创建类型
UPDATE: I tried copy pasting the above mentioned files in the "jni" folder and built using ndk-build. Building was successful and also no crashes at the runtime. But, socket creation of type
socket(AF_NETLINK, SOCK_DGRAM, NETLINK_INET_DIAG)
与错误EACCES失败(13) - 权限创建指定类型和/或协议的插座被拒绝
is failing with error EACCES(13) - Permission to create a socket of the specified type and/or protocol is denied.
任何建议如何进一步开展?
Any suggestions how to proceed further?
推荐答案
在Android的棒棒糖,安全增强的Linux(SELinux)的Android中的强制模式已启用。通过观察/看沙盘定义 Android源$ C $ C - 的SE政策在app.te(粘贴下面节选),也不会有任何支持网络链路插槽。
In Android Lollipop, Security Enhanced Linux (SELinux) in Android is enabled in "enforce" mode. By observing/looking at the sandbox definitions Android Source Code - SE Policy of the app.te (Below pasted excerpt), there will not be any supports for the netlink sockets.
# Privileged netlink socket interfaces.
neverallow appdomain
self:{
netlink_socket
netlink_firewall_socket
netlink_tcpdiag_socket
netlink_nflog_socket
netlink_xfrm_socket
netlink_audit_socket
netlink_ip6fw_socket
netlink_dnrt_socket
} *;
这篇关于网络链路实现为Android NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!