摘要: 一、下面分析client端的认证函数(认证过程就是隧道建立过程) 函数client和server分别在文件client.c和server.c中,先分析client. if( (s = socket(AF_INET,SOCK_STREAM,0))==-1 )。。。 隧道使用sock_STREAM建立的,但是隧道中数据的传输可用TCP也可用UDP。 if( bind(s,(struct sockadd... 阅读全文
posted @ 2012-09-23 22:03 helloweworld 阅读(1089) 评论(0) 推荐(0) 编辑
摘要: 头文件:#include <sys/types.h>#include <unistd.h>#include <fcntl.h>原型:int fcntl(int fd , int cmd,...);参数:变参函数,根据cmd来判断第三个参数。功能:fcntl()用来操作文件描述符的一些特性。fcntl 不仅可以施加建议性锁,还可以施加强制锁。同时,fcntl还能对文件的某一记录进行上锁,也就是记录锁。cmd: F_DUPFD用来查找大于或等于参数arg的最小且仍未使用的文件描述词,并且复制参数fd的文件描述词。执行成功则返回新复制的文件描述词。新描述符与fd共 阅读全文
posted @ 2012-09-23 20:34 helloweworld 阅读(342) 评论(0) 推荐(0) 编辑
摘要: ssize_t read(int fd,void * buf ,size_t count);将fd中内容读出写到buf。返回值:如果实际读的字节数<count,返回实际读的字节数;如果实际fd中字节数>count,返回count.错误返回-1.一般正常情况下,返回的就是count,但是有可能由于信号中断或读到文件尾等原因,读的字节数可能<count.无论如何,返回值<=count.write同。 阅读全文
posted @ 2012-09-23 20:34 helloweworld 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 1、UDP(1)client.c#include &lt;stdio.h> #include <stdlib.h> #include <string.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/socket.h> #defin 阅读全文
posted @ 2012-09-23 20:07 helloweworld 阅读(416) 评论(0) 推荐(0) 编辑
摘要: 1、find / -name "*" | xargs grep "route"在根文件夹下查找含有关键字route的文件,列出文件名和route所在行。2、find / -name "*.txt" | xargs grep "route"在根文件夹下查找后缀名为txt且含有关键字route的文件,列... 阅读全文
posted @ 2012-09-23 15:43 helloweworld 阅读(1787) 评论(0) 推荐(0) 编辑
摘要: 打开或创建文件:c++1234567891011121314151617181920212223242526272829303132333435363738394041424344/***********打开或创建文件**************头文件:#include<stdio.h>原型: FILE *fopen(const char *path,const char *mode); 功能:打开或创建文件。参数:mode有下列几种字符串,r 打开只读文件,该文件必须存在。r+ 打开可读写的文件,该文件必须存在。w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若 阅读全文
posted @ 2012-09-23 14:50 helloweworld 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 1/*头文件:/* According to POSIX.1-2001 */#include <sys/select.h> /* According to earlier standards */#include <sys/time.h>#include <sys/types.h>#include <unistd.h>原型:int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); int pselect( 阅读全文
posted @ 2012-09-23 13:20 helloweworld 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 怀疑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 阅读(1182) 评论(0) 推荐(0) 编辑