09 2012 档案

摘要:UDP系统调用时序图简单的UDP例子/* ============================================================================ Name : UDPclient.c Author : vestinfo Version : 1.1 Copyright : Your copyright notice Description : A simple UDP client, Ansi-style =====================================================... 阅读全文
posted @ 2012-09-30 22:43 helloweworld 阅读(1141) 评论(0) 推荐(0)
摘要:TCP 套接字函数,系统调用时序图connect函数头文件:#include <sys/socket.h>原型:int connect(int sockfd, const struct sockaddr* servaddr, socklen_t addrlen);参数:sockfd是socket函数返回的套接字描述符,servaddr指向套接字地址结构的指针(理解为对端的地址), addrlen该结构的大小,可通过sizeof(struct sockaddr)获得。返回值:成功返回0,出错返回-1.功能:建立socket连接。备注:(1)client在调用connect前不必非得调 阅读全文
posted @ 2012-09-30 21:56 helloweworld 阅读(1348) 评论(4) 推荐(2)
摘要:在main函数中,reread_config(0); 经过下面的分析,知reread_config(0);是将每个会话信息作为一个结点存于host_list中(一个会话信息包含默认信息和本会话特有信息,且本会话信息会覆盖默认的相同选项)。 void reread_config(int sig){ if( !read_config(vtun.cfg_file) ) { vtun_syslog(LOG... 阅读全文
posted @ 2012-09-30 13:44 helloweworld 阅读(550) 评论(0) 推荐(0)
摘要:参考:http://www.ibm.com/developerworks/cn/linux/sdk/lex/#resources 阅读全文
posted @ 2012-09-29 21:34 helloweworld 阅读(804) 评论(0) 推荐(1)
摘要:声明:原创作品,转载注明出处http://www.cnblogs.com/vestinfo/一、简介推荐书籍《flex&bison》.在UNIX下是flex和bison.网上介绍很多,大部分是写给懂的人看的,初学者一头雾水。这样来理解lex和yacc可能容易些:在linux下,有很多系统配置文件,一些linux下的软件也有配置文件,那么程序是如何读取配置文件中的信息的呢?首先用到lex词法分析器,读取配置文件中的关键词(后面说到的token标记其实可看做关键词)。然后把关键词递交给yacc,yacc对一些关键词进行匹配,看是否符合一定语法逻辑,如果符合就进行相应动作。上面举得例子是分析 阅读全文
posted @ 2012-09-29 21:29 helloweworld 阅读(3716) 评论(0) 推荐(3)
摘要:声明:原创作品,转载注明出处:http://www.cnblogs.com/vestinfo/六、flex和bison相结合。test.l%{ #include "test.tab.h" #include <stdio.h> #include <stdlib.h> %} %% a {return A_STATE;} b {return B_STATE;} c {return C_STATE;} not {return NOT;} %%test.y%{ #include <stdio.h> #include <stdlib.h> 阅读全文
posted @ 2012-09-29 10:02 helloweworld 阅读(923) 评论(0) 推荐(1)
摘要:struct llist_element { struct llist_element * next; void * data;}; typedef struct llist_element llist_elm; llist_elm是一个链表型结点。 typedef struct { llist_elm * head; llist_elm * tail;} llist; llist结构体中... 阅读全文
posted @ 2012-09-27 17:22 helloweworld 阅读(164) 评论(0) 推荐(0)
摘要:认证即隧道的建立用TCP套接字,之后根据配置文件选择合适协议传输。 clinet隧道建立套接字和传输套接字替换 1、在clinet函数中 s = socket(AF_INET,SOCK_STREAM,0); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); bind(s,(struct sockaddr *)&my_addr,s... 阅读全文
posted @ 2012-09-27 15:34 helloweworld 阅读(359) 评论(0) 推荐(0)
摘要:只分析udp, 单独运行clinet,处于connect状态,并没有运行到tunnel这个步骤,单独运行client时没出现虚拟网卡; 单独运行server,处于listen状态,也没运行到tunnel这个步骤,所以单独运行server也不会出现虚拟新网卡。 当server端开启,处于监听状态,这时client请求连接,认证成功后client和server才会进入tunnel执行打开虚拟网卡, ... 阅读全文
posted @ 2012-09-27 12:11 helloweworld 阅读(874) 评论(0) 推荐(0)
摘要:一、syslog(),openlog(),closelog()一套用于写系统日志的函数。这三个函数openlog, syslog, closelog是一套系统日志写入接口,另外那个vsyslog和syslog功能一样,只是参数格式不同。通常,syslog守护进程读取三种格式的记录消息。此守护进程在启动时读一个配置文件。一般来说,其文件名为/etc/syslog.conf,该文件决定了不同种类的消息应送向何处。例如,紧急消息可被送向系统管理员(若已登录),并在控制台上显示,而警告消息则可记录到一个文件中。该机制提供了syslog函数,其调用格式如下#include <syslog.h> 阅读全文
posted @ 2012-09-27 10:31 helloweworld 阅读(2495) 评论(0) 推荐(0)
摘要:openlog("vtund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); 打开系统记录 在lib.c中定义, void vtun_syslog (int priority, char *format, ...) { static volatile sig_atomic_t in_syslog= 0; char buf[255]; va... 阅读全文
posted @ 2012-09-27 09:04 helloweworld 阅读(322) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2012-09-26 22:31 helloweworld 阅读(216) 评论(0) 推荐(0)
摘要:1、__io_canceled在lib.h中定义, /* IO cancelation */extern volatile sig_atomic_t __io_canceled; __io_canceled变量影响下列函数, static inline int read_n(int fd, char *buf, int len){ register int t=0, w; while (!_... 阅读全文
posted @ 2012-09-26 16:33 helloweworld 阅读(423) 评论(0) 推荐(0)
摘要:在main函数中,有一行, clear_nat_hack_flags(svr); 在cfg_file.y中定义, /* Clear the VTUN_NAT_HACK flag which are not relevant to the current operation mode */inline void clear_nat_hack_flags(int svr){ if (svr) llis... 阅读全文
posted @ 2012-09-26 15:36 helloweworld 阅读(569) 评论(0) 推荐(0)
摘要:dpkg –L *** root@ubuntu:~# dpkg -L vtun/./usr/usr/sbin/usr/sbin/vtund/usr/share/usr/share/lintian/usr/share/lintian/overrides/usr/share/lintian/overrides/vtun/usr/share/man/usr/share/man/man8/usr/shar... 阅读全文
posted @ 2012-09-26 10:12 helloweworld 阅读(322) 评论(0) 推荐(0)
摘要:声明:转载注明出处! 注: 1、 PID文件 the pid files contains the process id (a number) of a given program. For example, Apache HTTPD may write it's main process number to a pid file - which is a regular text file,... 阅读全文
posted @ 2012-09-25 21:23 helloweworld 阅读(363) 评论(0) 推荐(0)
摘要:头文件:#include <unistd.h>int dup(int fd);int dup(int fd1,int fd2);功能:复制一个现存的文件描述符,返回新的文件描述符。返回值,成功返回新的文件描述符,出错返回-1.由dup返回的新文件描述符一定是当前可用文件描述中的最小数值。用dup2则可以用fd2参数指定新的描述符数值。如果fd2已经打开,则先关闭。若fd1=fd2,则dup2返回fd2,而不关闭它。通常使用这两个系统调用来重定向一个打开的文件描述符。 阅读全文
posted @ 2012-09-25 11:04 helloweworld 阅读(321) 评论(0) 推荐(0)
摘要:头文件:#include<unistd.h>#include<sys/types.h>原型:pid_t fork( void);返回值:若成功调用一次则返回两个值,子进程返回0,父进程返回子进程ID;否则,出错返回-1.功能:一个现有进程可以调用fork函数创建一个新进程。由fork创建的新进程被称为子进程(child process)。fork函数被调用一次但返回两次。两次返回的唯一区别是子进程中返回0值而父进程中返回子进程ID。举例1234567891011121314151617181920212223#include<sys/types.h>//对于 阅读全文
posted @ 2012-09-25 10:57 helloweworld 阅读(358) 评论(0) 推荐(0)
摘要:上一篇分析了linkfd.c的lfd_linker()函数中的while在不考虑信号中断的情况下一直在执行(执行的是虚拟网卡的读写和数据的发送接收)。 而决定是否一直循环执行的linker_term变量被信号处理函数改变了,下面分析linker_term在哪些信号处理函数中被改变了,以及信号处理函数在干嘛。 在linkfd.c中, /* Termination flag */ static voi... 阅读全文
posted @ 2012-09-24 21:43 helloweworld 阅读(430) 评论(0) 推荐(0)
摘要:头文件:#include <signal.h>原型:int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);参数:signum是除了SIGKILL和SIGSTOP之外的任何信号;act非空,新的动作(信号到来时执行的函数)存在act中,如果旧的动作非空,旧动作存在oldact中;返回值:sigaction() returns 0 on success and -1 on error.sigaction结构体如下:struct sigaction { void (*sa_hand 阅读全文
posted @ 2012-09-24 15:19 helloweworld 阅读(881) 评论(0) 推荐(0)
摘要:在文件linkfd.c文件中,有从虚拟网卡读出数据然后发送,将接收到的数据写入网卡过程。 注意,在client和server端,上面的两个过程都有,意思可以说是两端对等,看下图。 下面分析对虚拟网卡的读写非阻塞问题,在linkfd.c的lfd_linker函数中,(client和server都是用该函数完成对虚拟网卡的读写)。 主要是下面代码: while( !linker_term )//w... 阅读全文
posted @ 2012-09-24 11:38 helloweworld 阅读(473) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2012-09-24 10:16 helloweworld 阅读(302) 评论(0) 推荐(0)
摘要:下面分析使用UDP封装数据包发送流程,从udp的socket创建开始分析, client中调用tunnel函数,tunnel中调用linkfd完成数据的发送。 发送数据流程都在linkfd.c中,这里的发送指的是从虚拟网卡读出数据,作为新建socket的数据部分发送。 linkfd函数中调用lfd_linker函数,其中有数据包的发送函数, if( len && proto_write(fd1, out, len) < 0 ) 那么建立数据包的和连接的过程在哪里?这就要分析fd1了, 下面分析fd1, int fd1 = lfd_host->rmt_fd; 找lfd 阅读全文
posted @ 2012-09-23 22:29 helloweworld 阅读(412) 评论(0) 推荐(0)
摘要:一、下面分析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 阅读(1172) 评论(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 阅读(365) 评论(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 阅读(388) 评论(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 阅读(433) 评论(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 阅读(1819) 评论(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 阅读(312) 评论(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 阅读(251) 评论(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 阅读(601) 评论(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 阅读(297) 评论(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 阅读(1231) 评论(0) 推荐(0)
摘要:在tun_dev.c中定义: int tun_write(int fd, char *buf, int len){ return write(fd, buf, len);} int tun_read(int fd, char *buf, int len){ return read(fd, buf, len);} 阅读全文
posted @ 2012-09-21 10:04 helloweworld 阅读(600) 评论(0) 推荐(0)
摘要:vtun如何解析启动客户端或服务器的命令行参数?Usage: Server: vtund <-s> [-f file] [-P port] [-L local address] Client: vtund [-f file] [-p] [-m] [-t timeout] <host profile> <server address>预备知识:-s –f –P 等称为选项;file port称为选项对应的参数;host file server address ——暂且称它们为非选项字符串吧。解析代码在main.c中。在vtun源码中是这样实现的:1234567 阅读全文
posted @ 2012-09-20 20:07 helloweworld 阅读(1854) 评论(0) 推荐(0)
摘要:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162/*原型:int getopt(int argc, char * const argv[], const char *optstring);四个全局变量:extern char *optarg; //指向选项的参数的指针。extern int optind, //存储位置,下一次调用getopt的时,从optind存储的位置处重新开始检查选项。extern int o 阅读全文
posted @ 2012-09-20 19:04 helloweworld 阅读(802) 评论(0) 推荐(0)
摘要:1234567891011121314151617181920212223/**********************Name:a.outAuthor:不学则死Date:2012/9/20CopyRight:转载注明出处***********************//*argc是整个命令行参数的个数;argv[0] 指向程序运行的全路径名;argv[1] 指向执行程序名后的第一个字符串;argv[2] 指向执行程序名后的第二个字符串;...argv[argc]为NULL。*/#include<stdio.h>intmain(int argc, char** argv) { in 阅读全文
posted @ 2012-09-20 15:27 helloweworld 阅读(347) 评论(0) 推荐(1)
摘要:一般步骤: #gcc –g test.c #l #break <行号> #r #n 要用gdb调试,在编译时要加-g选项。 如: #gcc –g test.c #gdb a.out 运行时要加入参数: 进入gdb后输入(gdb)run 参数1 参数2 ….即可 对应vtun即 #gdb vtund (gdb)r server [vtun服务器地址] 阅读全文
posted @ 2012-09-20 10:16 helloweworld 阅读(544) 评论(0) 推荐(0)
摘要:#gdb vtund (gdb)break 57 (gdb)r (gdb)n … vtund[4904]: Unknown option 'pass' line 12vtund[4904]: No hosts defined 原因:默认读/usr/local/etc/vtund.conf,此文件中的12行pass应该为passwd, 解决:将配置成功的的文件替换默认读的文件 阅读全文
posted @ 2012-09-20 10:11 helloweworld 阅读(352) 评论(0) 推荐(0)
摘要:3.0.3 双系统 #./configure –-disable-lzo #make install vm安装提示找不到strip 解决方法:cp /usr/bin/strip /usr/local/bin vm安装3.0.1同上 阅读全文
posted @ 2012-09-19 22:46 helloweworld 阅读(368) 评论(0) 推荐(0)
摘要:http://wiki.ubuntu.org.cn/index.php?title=%E8%B7%9F%E6%88%91%E4%B8%80%E8%B5%B7%E5%86%99Makefile:MakeFile%E4%BB%8B%E7%BB%8D&variant=zh-cn 阅读全文
posted @ 2012-09-19 15:02 helloweworld 阅读(133) 评论(0) 推荐(0)
摘要:四个阶段:预编译、编译、汇编和链接。阶段输入输出工具示例预编译*.c*.i预处理器cppgcc –E test.c –o test.i编译*.i*.s 汇编代码编译器egcsgcc –S test.i –o test.s汇编*.s*.o 目标代码汇编器asgcc –c test.s –o test.o链接*.o可执行文件连接器ldgcc test.o –o test简单理解:预编译:替换宏定义的变量和include包含以及进行条件编译;即如#define PI 3.1415,则将文件中的PI用3.1415替换,include文件包含和条件编译同理。编译:生成汇编语言。汇编:生成机器语言。链接: 阅读全文
posted @ 2012-09-19 14:13 helloweworld 阅读(254) 评论(0) 推荐(0)
摘要:一、客户端 options{port5000;#Listenonthisport.ppp/usr/sbin/pppd;ifconfig/sbin/ifconfig;route/sbin/route;firewall/sbin/iptables;}server{passwdMa&^TU;#Passwordkeepaliveyes;#Keepconnectionalivetypetun;protoud... 阅读全文
posted @ 2012-09-18 22:30 helloweworld 阅读(913) 评论(0) 推荐(0)
摘要:ListView的每个Item 都有圆角外边框。 一、首先看效果图 二、文档结构 1、main.xml中有一个ListView控件; 2、main_vlist.xml是ListView中的每个Item控件布局, 3、在main_vlist.xml的最外层父元素的背景设为圆角边框awable/rounded_corner_border。 android:background="@drawable... 阅读全文
posted @ 2012-09-18 11:58 helloweworld 阅读(579) 评论(0) 推荐(0)
摘要:VC6.0编译通过,eclipse没有通过。12345678910111213141516171819202122232425262728#include<iostream>usingnamespace std;//int max(int x, int y)//{// cout << "调用int max(int x, int y);" << endl;// return x > y ? x : y;//}//float max(float x, float y)//{// cout << "调用float m 阅读全文
posted @ 2012-09-16 17:51 helloweworld 阅读(230) 评论(0) 推荐(0)
摘要:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 //============================================================================// Name : 大数取余.cpp... 阅读全文
posted @ 2012-09-16 16:34 helloweworld 阅读(2197) 评论(0) 推荐(0)
摘要:一、目标 JumpToPreferenceActivity.java跳转到MyPreferenceActivity.java. MyPreferenceActivity.java是应用设置Activity. 因为要和另一个项目关联,所以用了Intent,这里Intent纯粹鸡肋,关键是PreferenceActivity的使用。 二、工程文件结构 JumpToPreferenceActivity.... 阅读全文
posted @ 2012-09-15 19:16 helloweworld 阅读(327) 评论(0) 推荐(0)
摘要:1 /* 结构体名:iovec 名称含义:I/O向量 所在头文件:#include <sys/uio.h> 头文件中的定义: /* Structure for scatter/gather I/O. */ struct iovec { void *iov_base; /* Pointer to data. */ size_t iov_len; /* Length of data. */ };说明:成员iov_base指向一个缓冲区,这个缓冲区是存放readv所接收的数据或是writev将要发送的数据。iov_len确定了接收的最大长度以及实际写入的长度。readv和wirtev是r 阅读全文
posted @ 2012-09-14 21:22 helloweworld 阅读(1388) 评论(0) 推荐(0)
摘要:1 /* 一般格式:typedef <类型> <标识符1> [,<标识符2>...]; 类型为基本类型名,或自定义类型名(如结构体类型名),或是已重定义的类型名; 标识符可做类型说明符或强制类型转换的类型标识符。 例子: typedef int LENGTH; //A typedef char* STRING; //B typedef int VEC[50]; //C typedef struct node { //D char* word; int count; struct node *left,*right; }TREENODE,*TREEPTR; t 阅读全文
posted @ 2012-09-14 16:01 helloweworld 阅读(1569) 评论(0) 推荐(0)
摘要:1 /* #include <sys/types.h>#include <sys/socket.h>原型:int setsockopt(int sockfd, int level, int optname,const void *optval, socklen_t optlen); 功能:设置套接字状态。参数:sockfd:标识一个套接口的描述字。 level:选项定义的层次;支持SOL_SOCKET、IPPROTO_TCP、IPPROTO_IP和IPPROTO_IPV6。 optname:需设置的选项。 optval:指针,指向存放选项值的缓冲区。 optlen:op 阅读全文
posted @ 2012-09-14 14:47 helloweworld 阅读(391) 评论(0) 推荐(0)
摘要:IPv4中使用gethostbyname()函数完成主机名到地址解析,这个函数仅仅支持IPv4,且不允许调用者指定所需地址类型的任何信息,返回的结构只包含了用于存储IPv4地址的空间。IPv6中引入了getaddrinfo()的新API,它是协议无关的,既可用于IPv4也可用于IPv6。getaddrinfo函数能够处理名字到地址以及服务到端口这两种转换,返回的是一个addrinfo的结构(列表)指针而不是一个地址清单。这些addrinfo结构随后可由套接口函数直接使用。如此以来,getaddrinfo函数把协议相关性安全隐藏在这个库函数内部。应用程序只要处理由getaddrinfo函数填写的 阅读全文
posted @ 2012-09-14 11:45 helloweworld 阅读(1201) 评论(0) 推荐(0)
摘要:一、void型指针1、void型指针也称为无类型指针,可以把任意类型的指针值赋给它;2、但若加void型指针付给其他类型的指针变量时,必须做强制类型转换。3、void类型指针主要用途是编写通用的函数。二、函数指针(指向函数的指针)例1:void myFun(int x);是函数声明。void (*funp)(int);是定义一个指向函数的指针。注:函数指针——指向函数的指针,指针函数——函数的返回值是指针。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include<iostream> usingnamespace s 阅读全文
posted @ 2012-09-13 15:46 helloweworld 阅读(1451) 评论(0) 推荐(0)
摘要:1 2 3 4 5 6 7 8 /* 一、指针指向的变量的值不能变,指向可变 int x = 1; int y = 2; const int* px = &x; int const* px = &x; //这两句表达式一样效果 px = &y; //正确,允许改变指向 *px = 3; //错误,不允许改变指针指向的变量的值 */ /* 二、指针指向的变量的值可以改变,指向不可变 int x = 1; int y = 2; int* const px = &x; px = &y; //错误,不允许改变指针指向 *px = 3; //正确,允许改变指针指向 阅读全文
posted @ 2012-09-13 11:48 helloweworld 阅读(159) 评论(0) 推荐(0)
摘要:1 #include <sys/time.h> /* 原型: int gettimeofday( struct timeval *tv, struct timezone *tz ); 功能: 获取当前精确时间。在一段代码前后分别使用gettimeofday可以计算代码执行时间. 参数: 其参数tv是保存获取时间结果的结构体,参数tz用于保存时区结果(若不使用则传入NULL即可)。 返回值:成功则返回0,失败返回-1,错误代码存于errno struct timeval {long tv_sec; // 秒数long tv_usec; // 微秒数}struct timezone{ 阅读全文
posted @ 2012-09-12 22:08 helloweworld 阅读(628) 评论(0) 推荐(0)
摘要:1 #include <arpa/inet.h> /* 表达式格式(presentation):形如192.168.0.1,ipv6 X:X:X:X:X:X:X:X 数值格式(numeric):存储地址的二进制形式。 */ /* 原型:int inet_pton( int family, const char *strptr, void *addrptr ); 功能:将字符串strptr(即表达格式的地址)转换为网络地址。 参数:family既可以是AF_INET,也可以是AF_INET6; strptr指向ASCII地址的首地址(***.***.***.***格式),addrpt 阅读全文
posted @ 2012-09-12 21:30 helloweworld 阅读(1097) 评论(0) 推荐(0)
摘要:一、IPV4套接字地址结构#include<netinet/in.h> /**IPV4套接字地址结构**/ structin_addr { in_addrs_addr;//32位IPV4地址,这是无符号整数,网络字节序 }; /*POSIX只关注sin_family,sin_port,sin_addr,所有网络套接字地质结构都至少16字节*/ structsockaddr_in { uint8_tsin_len;//无符号八位整形,套接字地址长度(16字节) sa_family_tsin_family;//unsignedshort in_port_tsin_port;//16位T 阅读全文
posted @ 2012-09-12 20:25 helloweworld 阅读(737) 评论(0) 推荐(0)
摘要:先CTRL+B(Project->Build all)再CTRL+F11; 阅读全文
posted @ 2012-09-11 23:23 helloweworld 阅读(256) 评论(0) 推荐(0)
摘要:法一:直接新立得。法二:我的电脑D:\eclipse linux cc++ 版本 安装包拷贝到ubuntu中。1、终端到拷贝的目录下 ./jdk-6u13-linux-i586.bin2、./eclipse3、如果提示jre啥的找不到,吧1中的相应文件拷贝到提示的位置即可。 阅读全文
posted @ 2012-09-11 23:15 helloweworld 阅读(166) 评论(0) 推荐(0)
摘要:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include<stdio.h> #include<string.h> #include<stdarg.h> intdemo( char* msg, ... ) { va_list argp; //1、va_list变量是指向参数的指针; char* para; va_start( argp, msg ); //2、va_start(argp,msg)获取可变参数列表的第一个参数地址,此例即msg参数的地址; //arg 阅读全文
posted @ 2012-09-11 23:00 helloweworld 阅读(445) 评论(0) 推荐(0)
摘要:函数名:vsnprintf原型:int _vsnprintf(char *buffer, size_t max_count, const char *format, va_list vArgList);功能:类同vsprintf,加了max_count限制。参数:返回值:如果成功调用此函数,返回写到buffer中的字符的个数(不包括结尾的'\0')。snprintf和vsnprintf函数不能够写多于size大小(包括结尾的'0')的字节数。如果输出因为以上原因被截断,返回成功写入buffer的字符数(不包括结尾的'\0'),如果有足够的内存空间 阅读全文
posted @ 2012-09-11 20:51 helloweworld 阅读(1110) 评论(0) 推荐(0)
摘要:函数:syslog()功能:记录至系统记录。头文件:#include <syslog.h>语法: int syslog(int priority, string message);返回值: 整数函数种类: 操作系统与环境内容说明 :本函数将 message 字符串写到系统纪录中,参数 priority 的值可能为 LOG_EMERG、LOG_ALERT、LOG_CRIT、LOG_ERR、LOG_WARNING、LOG_NOTICE、LOG_INFO、 LOG_DEBUG。本函数呼叫 UNIX 操作系统的 syslog() 函数,在 Windows NT 上,使用事件检视器模拟出本功 阅读全文
posted @ 2012-09-11 20:33 helloweworld 阅读(351) 评论(0) 推荐(0)
摘要:在源代码中经常会出现下面一些错误处理函数。一、errno头文件:#include <errno.h>函数原型:errno功能:记录系统的最后一次错误代码参数:无返回值:错误代号(整型值)例子:1 2 3 4 5 if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { fprintf(stderr, "errno = %d \n", errno); exit(1); } printf("Socket opened successfully \n"); //errno 返回整型错误代号。 二、s 阅读全文
posted @ 2012-09-11 20:13 helloweworld 阅读(1959) 评论(0) 推荐(0)
摘要:一、简介1、编译预处理命令均以#开头,以回车符结束;2、每条预处理命令独占一行;3、可以出现在程序的任意位置,但通常置于源程序的开始;4、在C++编译对源程序进行编译之前,先对程序中这些命令进行预处理;5、C++预处理主要有三种:文件包含、宏定义和条件编译。二、文件包含1、格式格式1:#include <filename>C++编译系统预定义的包含文件,这些文件在c++编译系统的include目录或其子目录中,通知预处理程序按系统规定路径检索文件。格式2:#include “filename”从当前工作目录开始查找,一般为自定义头文件。2、预处理程序对源文件进行扫描时,将产生一个临 阅读全文
posted @ 2012-09-11 15:28 helloweworld 阅读(571) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2012-09-10 11:02 helloweworld 阅读(851) 评论(0) 推荐(0)
摘要:背景透明色 android:background=”#00000000” 图片空心(图片部分透明) ps中以背景透明作图即可 我的项目资源文件关系 layout文件夹下: main.xml 是主界面布局 main_title.xml 是主界面标题栏布局 mail... 阅读全文
posted @ 2012-09-09 20:59 helloweworld 阅读(724) 评论(0) 推荐(0)
摘要:1 2 3 4 5 6 7 8 9 10 11 12 ... 阅读全文
posted @ 2012-09-09 15:32 helloweworld 阅读(1282) 评论(0) 推荐(0)
摘要:http://blog.sina.com.cn/s/blog_72fad6270100x7k2.html styles.xml放在res/values文件夹中 具体放在哪里,这要深入了解android中关于资源引用的部分 一般情况下(除values文件夹),res文件夹下的子文件夹都对应R.java中的一个内部类,类名就是该子文件夹的名字; 子文件夹下的资源项都对应内部类的一个int... 阅读全文
posted @ 2012-09-08 13:47 helloweworld 阅读(377) 评论(0) 推荐(0)
摘要:一、简介 1、android五大布局:LinearLayout 、TableLayout、RelativeLayout、FrameLayout、AbsoluteLayout 2、 LinearLayout以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高... 阅读全文
posted @ 2012-09-07 20:41 helloweworld 阅读(520) 评论(0) 推荐(0)
摘要:讲解Context的一篇不错的文章http://www.cppblog.com/life02/archive/2012/03/19/168328.aspx 调用service时需要一个Context实例! 1 2 3 4 ... 阅读全文
posted @ 2012-09-07 17:23 helloweworld 阅读(186) 评论(0) 推荐(0)
摘要:android pull解析豆瓣图书xml <?xmlversion="1.0"encoding="UTF-8"?> <entryxmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:opensearch="http://a9.... 阅读全文
posted @ 2012-09-04 14:33 helloweworld 阅读(287) 评论(0) 推荐(0)
摘要:前期配置http://bbs.chinaunix.net/thread-3768139-1-1.html 1、根据文章http://blog.csdn.net/wangxing1018/article/details/3349557 里有这么一段话 “ 当然了,如果还想访问服务器的内网,可可以再添加路由项如下: route "add -net 192.168.0.0 netmask 25... 阅读全文
posted @ 2012-09-04 11:47 helloweworld 阅读(303) 评论(0) 推荐(0)
摘要:1、拔掉数据线; 2、PC控制台输入:adb kill-server; 3、插入数据线,等待设备就绪,大约几秒钟; 4、PC控制台输入:adb devices。 注:如果输入adb 提示找不到命令,请配置环境变量,略。 阅读全文
posted @ 2012-09-03 21:52 helloweworld 阅读(185) 评论(0) 推荐(0)
摘要:此文是本人根据自己的理解以及对网络内容的参考而作,参考见文章最后,理解不当之处,恳请指正,万分感谢! 要解决的问题: Activity的跳转顺序为FirstActivity—>SecondActivity—>ThirdActivity。 问题一: 1、在FirstActivity中双击返回键退出程序; 2、在SecondActivity中按返回键回到FirstAcitivity; 3、在ThirdActivity中按返回键回到SecondActivity。 问题二: 1、在FirstActivity中双击返回键退出程序; 2、在SecondActivity中按返回键回到FirstA 阅读全文
posted @ 2012-09-01 16:09 helloweworld 阅读(789) 评论(0) 推荐(0)