摘要: 怀疑vtun就是将虚拟网卡中的数据读出,然后新建socket发送该数据的。 从上一篇看到了数据包的发送和接收是通过调用 proto_write proto_read两个函数实现的,那么我们就来看这两个函数,进一步了解vtun是如何封装和解封也即发送接收数据的。 一、proto_write封装分析 proto_write是函数指针,在tunnel.c中: proto_write = udp_write;proto_read = udp_read; 先看udp_write函数,udp_proto.c中: /* Functions to read/write UDP frames. */in... 阅读全文
posted @ 2012-09-22 22:45 helloweworld 阅读(565) 评论(0) 推荐(0) 编辑
摘要: 用于计算操作数类型占用内存的字节数。32位机,sizeof(int) 4sizeof(float) 4sizeof(‘\100’) 1 (转义)sizeof(‘a’ + 2.5) 8 (double)sizeof(“hello”) 6sizeof(1+2) 4 阅读全文
posted @ 2012-09-22 22:17 helloweworld 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 一、对虚拟网卡的读写操作都在哪里? 对虚拟网卡写操作函数tun_write在tun_dev.c中定义; 函数指针dev_write在tunnel.c中指向tun_write函数; 函数指针dev_write在linkfd.c中对虚拟网卡进行写操作。 因此实际对虚拟网卡的写操作在linkfd.c中。 涉及到写操作的linkfd.c中的代码: if( len && dev_write(fd2,ou... 阅读全文
posted @ 2012-09-22 13:17 helloweworld 阅读(1191) 评论(0) 推荐(0) 编辑