android 層以上比較簡單,有空補上。從JNI開始
static jstring android_net_ethernet_waitForEvent(JNIEnv *env,
jobject clazz){
if((len = recvmsg(nl_socket_poll, &msg, 0))>= 0)
}
static jint android_net_ethernet_initEthernetNative(JNIEnv *env,
jobject clazz)
{
/*
*Create connection to netlink socket
*/
nl_socket_msg = socket(AF_NETLINK,SOCK_RAW,NETLINK_ROUTE);
}
內核部分:
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
{
retval = sock_create(family, type, protocol, &sock);
}
static int __sock_create(struct net *net, int family, int type, int protocol,
struct socket **res, int kern)
{
pf = rcu_dereference(net_families[family]);
/*
* We will call the ->create function, that possibly is in a loadable
* module, so we have to bump that loadable module refcnt first.
*/
err = pf->create(net, sock, protocol, kern);
}
net_families哪裏來的??look here
static int __init netlink_proto_init(void)
{
sock_register(&netlink_family_ops);
}
int sock_register(const struct net_proto_family *ops)
{
spin_lock(&net_family_lock);
if (net_families[ops->family])
err = -EEXIST;
else {
net_families[ops->family] = ops;
err = 0;
}
}