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;
}
}
本文详细介绍了Android层以上的基本概念,从JNI技术开始,深入探讨了内核部分的socket函数实现及其在创建网络连接过程中的作用。通过解析socket函数的内部实现,读者能够更好地理解底层通信机制。
3424

被折叠的 条评论
为什么被折叠?



