﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-winter729-随笔分类-Linux</title><link>http://www.cppblog.com/winter729/category/14567.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 19 Jan 2011 18:37:15 GMT</lastBuildDate><pubDate>Wed, 19 Jan 2011 18:37:15 GMT</pubDate><ttl>60</ttl><item><title>Ubuntu下配置redmine</title><link>http://www.cppblog.com/winter729/archive/2011/01/19/138840.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Wed, 19 Jan 2011 02:55:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2011/01/19/138840.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/138840.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2011/01/19/138840.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/138840.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/138840.html</trackback:ping><description><![CDATA[1,到 http://www.redmine.org 官网上下载最新的redmine。目前是1.1.0。将其解压至/opt/redmine 下<br>2,到 http://www.redmine.org/projects/redmine/wiki/RedmineInstall 查看需要的安装环境。<br>&nbsp;&nbsp; 一般需要rails 和rack <br>&nbsp; ：<code>gem install rails -v=2.3.5</code><br>&nbsp; ：<code>gem install rack -v=1.0.1</code><br>3,安装mysql 数据库 ：sudo apt-get install mysql-server
。<br>&nbsp;&nbsp; 安装好后 进入mysql进行配置： mysql -u root (以后有密码了需要 输入 mysql -u root -p 按回车，再输入密码)<br>&nbsp;&nbsp; mysql&gt;grant all privileges on *.* to root@localhost identified by '123456';&nbsp;
//先设置root密码<br>&nbsp;&nbsp; mysql&gt;create database redmine character set utf8；
//必须要设置编码为utf8否则redmine所有汉字会显示成？？<br>&nbsp;&nbsp; mysql&gt;create user redmine@localhost identified by '123456'; //建立一个新用户redmine ，密码是123456<span style="font-family: monospace;"><br></span>&nbsp;&nbsp; mysql&gt;grant all privileges on redmine.* to redmine@localhost;<br>&nbsp;&nbsp; 这样mysql就配置好了。<br>4, 进入/opt/redmine 找到刚才解压的文件夹redmine-1.1.0 ，进入 config 目录下 将database.example.yml 复制为database.yml <br>&nbsp;&nbsp;&nbsp; sudo cp database.example.yml database.yml<br>&nbsp;&nbsp;&nbsp; sudo gedit database.yml<br>&nbsp;&nbsp;&nbsp; 按照如下修改<br>&nbsp;&nbsp;&nbsp;&nbsp; production:<br>&nbsp;&nbsp;&nbsp;&nbsp; adapter: mysql<br>&nbsp;&nbsp;&nbsp;&nbsp; socket: /var/run/mysqld/mysqld.sock<br>&nbsp;&nbsp;&nbsp;&nbsp; database: redmine<br>&nbsp;&nbsp;&nbsp;&nbsp; host: localhost<br>&nbsp;&nbsp;&nbsp;&nbsp; username: redmine<br>&nbsp;&nbsp;&nbsp;&nbsp; password: '123456'<br>&nbsp;&nbsp; &nbsp; encoding: utf8<br>5, 进入 /opt/redmine/redmine-1.1.0&nbsp; <br>&nbsp;&nbsp;&nbsp; 将redmine数据库导入到mysql数据库中 : <br>&nbsp;&nbsp;&nbsp; sudo rake generate session_store<br>&nbsp;&nbsp;&nbsp; sudo rake db:migrate RAILS_ENV =production<br>&nbsp;&nbsp;&nbsp; 如果导入顺利，就可以启动redmine了：<br>&nbsp;&nbsp;&nbsp; sudo ruby script/server -e production&nbsp; <br>6,打开ie浏览器，输入 ： http://localhost:3000 进入redmine 。默认用户名和密码是admin。在配置里面可以设置每个用户的语言，改成中文即可。<br><br><br>      <img src ="http://www.cppblog.com/winter729/aggbug/138840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2011-01-19 10:55 <a href="http://www.cppblog.com/winter729/archive/2011/01/19/138840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 下 实现一个简单的通信程序</title><link>http://www.cppblog.com/winter729/archive/2010/12/29/137687.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Wed, 29 Dec 2010 09:02:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/12/29/137687.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/137687.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/12/29/137687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/137687.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/137687.html</trackback:ping><description><![CDATA[用到了select，对select的了解更加深入了一些。<br>由于使用到了tcp链接，所以在发送的时候一定要关闭socket以使对端能收到EOF。<br><br>#include &lt;sys/types.h&gt;<br>#include &lt;ctype.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;stdarg.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;fcntl.h&gt;<br>#include &lt;sys/ioctl.h&gt;<br>#include &lt;errno.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;assert.h&gt;<br>#include &lt;pthread.h&gt;<br>#include &lt;sys/socket.h&gt;<br>#include &lt;netinet/in.h&gt;<br>#include &lt;netinet/ip.h&gt;<br>#include &lt;netinet/udp.h&gt;<br>#include &lt;netinet/tcp.h&gt;<br>#include &lt;arpa/inet.h&gt;<br>#include &lt;netdb.h&gt;<br>#include &lt;net/if.h&gt;<br>#include &lt;net/route.h&gt;<br>#include &lt;sys/stat.h&gt;<br>#include &lt;sys/epoll.h&gt;<br>#include &lt;sys/resource.h&gt;<br>#include &lt;sys/wait.h&gt;<br>#include &lt;dlfcn.h&gt;<br>#define LISTEN_PORT 25000<br>#define BUFFLEN 128<br>typedef struct Recv_Info<br>{<br>&nbsp;&nbsp;&nbsp; FILE * fconnectin;<br>&nbsp;&nbsp;&nbsp; char filepath[50];<br>}Recv_Info;<br>typedef struct Send_Info<br>{<br>&nbsp;&nbsp;&nbsp; char ip[50];<br>&nbsp;&nbsp;&nbsp; char filepath[50];<br>}Send_Info;<br><br>int listen_fd,connect_fd;<br>void handle_int ( int signo )<br>{<br>&nbsp;&nbsp;&nbsp; fprintf ( stderr, "Interrupt catched!!\n" );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; exit(0);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>}<br>static void* recieve_file(void * arg)<br>{<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; Recv_Info *recv_info = (Recv_Info*)arg;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; FILE * p;<br>&nbsp;&nbsp;&nbsp; p=fopen(recv_info-&gt;filepath,"w+");<br>&nbsp;&nbsp;&nbsp; if(p==NULL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout,"Fopen failed in recieve file! make sure your filepath is right!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; char buff[BUFFLEN];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int count=0;<br>&nbsp;&nbsp;&nbsp; int amount=0;<br>&nbsp;&nbsp;&nbsp; while(fgets(buff,BUFFLEN,recv_info-&gt;fconnectin)!=NULL)<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=strlen(buff);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; amount+=count;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fputs(buff,p);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fprintf(stdout,"Recieve %d Bytes !\n",amount);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fclose(p);<br>&nbsp;&nbsp;&nbsp; close(connect_fd);<br>&nbsp;&nbsp;&nbsp; <br>}<br>static void* send_file(void * arg)<br>{<br>&nbsp;&nbsp;&nbsp; Send_Info * send_info=(Send_Info *)arg;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; char buff[BUFFLEN];<br>&nbsp;&nbsp;&nbsp; int remote_fd;<br>&nbsp;&nbsp;&nbsp; int remote_len;<br>&nbsp;&nbsp;&nbsp; struct sockaddr_in remote;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; FILE * p;<br>&nbsp;&nbsp;&nbsp; p=fopen(send_info-&gt;filepath,"r+");<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if(p==NULL)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout,"fopen failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; remote_fd = socket(AF_INET, SOCK_STREAM, 0);<br>&nbsp;&nbsp;&nbsp; if (remote_fd == -1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "socket() apply failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL;<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; memset(&amp;remote, 0, sizeof(remote));<br>&nbsp;&nbsp;&nbsp; remote.sin_family&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = AF_INET;<br>&nbsp;&nbsp;&nbsp; remote.sin_port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = htons(LISTEN_PORT);<br>&nbsp;&nbsp;&nbsp; remote.sin_addr.s_addr = inet_addr(send_info-&gt;ip);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int count = 0;<br>&nbsp;&nbsp;&nbsp; int amount = 0;<br>&nbsp;&nbsp;&nbsp; if(connect(remote_fd,(sockaddr*)&amp;remote,sizeof(sockaddr_in))==0)<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; send(remote_fd,"s",1,0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while(fgets(buff,BUFFLEN,p)!=NULL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count=send(remote_fd,buff,strlen(buff),0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; amount+=count;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout,"Send %d Bytes !\n",amount);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr,"errno:%d",errno);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; fclose(p);<br>&nbsp;&nbsp;&nbsp; close(remote_fd);<br>}<br>int main(int argc, char *argv[])<br>{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //init socket<br>&nbsp;&nbsp;&nbsp; struct sockaddr_in local;<br>&nbsp;&nbsp;&nbsp; int remote_len;<br>&nbsp;&nbsp;&nbsp; struct sockaddr_in remote;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int ret;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; pthread_t tid;<br>&nbsp;&nbsp;&nbsp; listen_fd = socket(AF_INET, SOCK_STREAM, 0);<br>&nbsp;&nbsp;&nbsp; if (listen_fd == -1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "socket() apply failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL ;<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; memset(&amp;local, 0, sizeof(local));<br>&nbsp;&nbsp;&nbsp; local.sin_family&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = AF_INET;<br>&nbsp;&nbsp;&nbsp; local.sin_port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = htons(LISTEN_PORT);<br>&nbsp;&nbsp;&nbsp; local.sin_addr.s_addr = htonl(INADDR_ANY);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if (bind(listen_fd, (struct sockaddr *)&amp;local, sizeof(local)) == -1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "bind failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(listen_fd);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL;<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if (listen(listen_fd, 5) == -1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "listen wrong!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(listen_fd);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; //init signal<br>&nbsp;&nbsp;&nbsp; struct sigaction act;<br>&nbsp;&nbsp;&nbsp; act.sa_handler = handle_int;<br>&nbsp;&nbsp;&nbsp; sigemptyset ( &amp;act.sa_mask );<br>&nbsp;&nbsp;&nbsp; act.sa_flags = 0;<br>&nbsp;&nbsp;&nbsp; sigaction ( SIGINT, &amp;act, NULL );<br>&nbsp;&nbsp;&nbsp; //////////////////<br>&nbsp;&nbsp;&nbsp; //message loop&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fprintf(stdout,"-Welcome to FeiGe! q to quit ,s filename ip to send ,p to input path-\n");&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //init select<br>&nbsp;&nbsp;&nbsp; fd_set rfds;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int retval;<br><br>&nbsp;&nbsp;&nbsp; FD_ZERO(&amp;rfds);<br>&nbsp;&nbsp;&nbsp; FD_SET(0, &amp;rfds);&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; FD_SET(listen_fd, &amp;rfds);&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; char buffstdin[100];<br>&nbsp;&nbsp;&nbsp; char * token;<br>&nbsp;&nbsp;&nbsp; FILE * fstdin;<br>&nbsp;&nbsp;&nbsp; Recv_Info recv_info; //used for recv thread<br>&nbsp;&nbsp;&nbsp; Send_Info send_info; //used for send thread<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fstdin=fdopen(0,"r+");<br>&nbsp;&nbsp;&nbsp; while ((retval = select(4, &amp;rfds, NULL, NULL, NULL)) &gt; 0)//begin the select loop<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(FD_ISSET(0,&amp;rfds))//stdin is ready<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fgets(buffstdin,100,fstdin);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //get input<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(buffstdin[0])&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //check the first charactor<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'q':<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit(0);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 's':&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //s means send<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memset(&amp;send_info,0,sizeof(Send_Info));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; token = strtok(buffstdin," "); // s<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; token = strtok(NULL," "); // filename<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memcpy(send_info.filepath,token,strlen(token));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; token = strtok(NULL,"\n"); // ip<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memcpy(send_info.ip,token,strlen(token));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ((ret = pthread_create(&amp;tid, NULL, send_file, (void *)&amp;send_info)) != 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "pthread_create() failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(connect_fd);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'p':&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //p means path<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; token = strtok(buffstdin," "); &nbsp;&nbsp;&nbsp; // get a p<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; token = strtok(NULL,"\n"); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // get path&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memcpy(recv_info.filepath,token,strlen(token));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ((ret = pthread_create(&amp;tid, NULL, recieve_file, (void *)&amp;recv_info)) != 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "pthread_create() failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(connect_fd);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(FD_ISSET(listen_fd,&amp;rfds))//listen fd is ready<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; remote_len = sizeof(remote);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memset(&amp;remote, 0, sizeof(remote));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; connect_fd = accept(listen_fd, (struct sockaddr *)&amp;remote, (socklen_t *)&amp;remote_len);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (connect_fd == -1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (errno == EINTR)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; continue;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stderr, "accept failed!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(listen_fd);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; memset(&amp;recv_info,0,sizeof(Recv_Info));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; recv_info.fconnectin=fdopen(connect_fd,"r+");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(fgetc(recv_info.fconnectin)!='s')<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; close(connect_fd);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout,"wrong format file incoming!\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(stdout,"A new file ,input a full path with p \n");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FD_ZERO(&amp;rfds);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FD_SET(0, &amp;rfds);&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FD_SET(listen_fd, &amp;rfds);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><img src ="http://www.cppblog.com/winter729/aggbug/137687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-12-29 17:02 <a href="http://www.cppblog.com/winter729/archive/2010/12/29/137687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用statfs 函数计算磁盘剩余空间</title><link>http://www.cppblog.com/winter729/archive/2010/10/29/131749.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Fri, 29 Oct 2010 07:13:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/10/29/131749.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/131749.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/10/29/131749.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/131749.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/131749.html</trackback:ping><description><![CDATA[如果想在程序里查看磁盘空间，就要用到statfs()函数。<br><br>查看指定路径下硬盘总空间和剩余空间大小的方法：<br><br>&nbsp;&nbsp;&nbsp; struct statfs diskInfo;<br>&nbsp;&nbsp;&nbsp; statfs("/",&amp;diskInfo);<br>&nbsp;&nbsp;&nbsp; unsigned long long blocksize = diskInfo.f_bsize;// 每个block里面包含的字节数<br>&nbsp;&nbsp;&nbsp; unsigned long long totalsize = blocksize * diskInfo.f_blocks;//总的字节数<br>&nbsp;&nbsp;&nbsp; printf("TOTAL_SIZE == %lu MB\n",totalsize&gt;&gt;20); // 1024*1024 =1MB&nbsp; 换算成MB单位<br><br>&nbsp;&nbsp;&nbsp; unsigned long long freeDisk = diskInfo.f_bfree*blocksize; //再计算下剩余的空间大小<br>&nbsp;&nbsp;&nbsp; printf("DISK_FREE == %ld MB\n",freeDisk&gt;&gt;20);<br><br><img src ="http://www.cppblog.com/winter729/aggbug/131749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-10-29 15:13 <a href="http://www.cppblog.com/winter729/archive/2010/10/29/131749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下各种printf函数的使用经验</title><link>http://www.cppblog.com/winter729/archive/2010/10/29/131719.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Fri, 29 Oct 2010 02:51:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/10/29/131719.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/131719.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/10/29/131719.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/131719.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/131719.html</trackback:ping><description><![CDATA[char * p="wow";<br><br>最基本的&nbsp;&nbsp; ：<br><br>printf（&#8220;hello %s&#8221;，p）<br><br>可以定向的：<br><br>fprintf(stdout,&#8220;hello %s \n&#8221;，p)&nbsp; //行缓冲 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>fprintf(stderr,&#8220;hello %s&nbsp; \n&#8221;，p)&nbsp; //不缓冲<br><br>可以输出到buf里的：<br><br>char buf[100];<br><br>snprintf(buf,&#8220;hello %s&nbsp; \n&#8221;，p);<br><br>&nbsp;字符格式：<br><br>%s :字符串<br>%x：十六进制<br>0x%.2x ：按照类似0xFF的格式显示十六进制<br>%lu： long unsigned<br>%llu:&nbsp;&nbsp; long long unsigned<br><br> <img src ="http://www.cppblog.com/winter729/aggbug/131719.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-10-29 10:51 <a href="http://www.cppblog.com/winter729/archive/2010/10/29/131719.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Base64编解码函数</title><link>http://www.cppblog.com/winter729/archive/2010/10/29/131718.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Fri, 29 Oct 2010 02:37:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/10/29/131718.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/131718.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/10/29/131718.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/131718.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/131718.html</trackback:ping><description><![CDATA[#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;string.h&gt;<br>//decode <br>const char Base64IdxTab[128] =<br>{<br><br>&nbsp;&nbsp;&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,<br><br>&nbsp;&nbsp;&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,<br><br>&nbsp;&nbsp;&nbsp; 255,255,255,255,&nbsp; 255,255,255,255,&nbsp; 255,255,255,62,&nbsp;&nbsp; 255,255,255,63,<br><br>&nbsp;&nbsp;&nbsp; 52,53,54,55,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 56,57,58,59,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60,61,255,255,&nbsp;&nbsp;&nbsp; 255,255,255,255,<br><br>&nbsp;&nbsp;&nbsp; 255,0,1,2,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3,4,5,6,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7,8,9,10,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 11,12,13,14,<br><br>&nbsp;&nbsp;&nbsp; 15,16,17,18,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 19,20,21,22,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 23,24,25,255,&nbsp;&nbsp;&nbsp;&nbsp; 255,255,255,255,<br><br>&nbsp;&nbsp;&nbsp; 255,26,27,28,&nbsp;&nbsp;&nbsp;&nbsp; 29,30,31,32,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 33,34,35,36,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 37,38,39,40,<br><br>&nbsp;&nbsp;&nbsp; 41,42,43,44,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 45,46,47,48,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 49,50,51,255,&nbsp;&nbsp;&nbsp;&nbsp; 255,255,255,255<br>};<br>#define BVal(x) Base64IdxTab[x]<br>int DecodeBase64(char * pInput, char * pOutput)<br>{<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i = 0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int iCnt = 0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int iSrcLen = (int)strlen(pInput);<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char * p = pOutput;<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0; i &lt; iSrcLen; i++)<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (pInput[i] &gt; 127) continue;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (pInput[i] == '=') return p-pOutput+1;<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a = BVal(pInput[i]);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (a == 255) continue;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch (iCnt)<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p = a &lt;&lt; 2;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iCnt++;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p++ |= a &gt;&gt; 4;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p = a &lt;&lt; 4;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iCnt++;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p++ |= a &gt;&gt; 2;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p = a &lt;&lt; 6;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iCnt++;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 3:<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p++ |= a;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; iCnt = 0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p = 0x00;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return p-pOutput;<br>}<br>//encode<br>const char Base64ValTab[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";<br>#define AVal(x) Base64ValTab[x]<br>int EncodeBase64(char * pInput, char * pOutput)<br>{<br>&nbsp;&nbsp;&nbsp; int i = 0;<br>&nbsp;&nbsp;&nbsp; int loop = 0;<br>&nbsp;&nbsp;&nbsp; int remain = 0;<br>&nbsp;&nbsp;&nbsp; int iDstLen = 0;<br>&nbsp;&nbsp;&nbsp; int iSrcLen = (int)strlen(pInput);<br><br>&nbsp;&nbsp;&nbsp; loop = iSrcLen/3;<br>&nbsp;&nbsp;&nbsp; remain = iSrcLen%3;<br><br>&nbsp;&nbsp;&nbsp; // also can encode native char one by one as decode method<br>&nbsp;&nbsp;&nbsp; // but because all of char in native string&nbsp; is to be encoded so encode 3-chars one time is easier.<br><br>&nbsp;&nbsp;&nbsp; for (i=0; i &lt; loop; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a1 = (pInput[i*3] &gt;&gt; 2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a2 = ( ((pInput[i*3] &amp; 0x03) &lt;&lt; 4) | (pInput[i*3+1] &gt;&gt; 4) );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a3 = ( ((pInput[i*3+1] &amp; 0x0F) &lt;&lt; 2) | ((pInput[i*3+2] &amp; 0xC0) &gt;&gt; 6) );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a4 = (pInput[i*3+2] &amp; 0x3F);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[i*4] = AVal(a1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[i*4+1] = AVal(a2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[i*4+2] = AVal(a3);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[i*4+3] = AVal(a4);<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; iDstLen = i*4;<br><br>&nbsp;&nbsp;&nbsp; if (remain == 1)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // should pad two equal sign<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i = iSrcLen-1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a1 = (pInput[i] &gt;&gt; 2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a2 = ((pInput[i] &amp; 0x03) &lt;&lt; 4);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = AVal(a1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = AVal(a2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = '=';<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = '=';<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen] = 0x00;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else if (remain == 2)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // should pad one equal sign<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i = iSrcLen-2;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a1 = (pInput[i] &gt;&gt; 2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a2 = ( ((pInput[i] &amp; 0x03) &lt;&lt; 4) | (pInput[i+1] &gt;&gt; 4));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char a3 = ( (pInput[i+1] &amp; 0x0F) &lt;&lt; 2);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = AVal(a1);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = AVal(a2);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = AVal(a3);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen++] = '=';<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen] = 0x00;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // just division by 3<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pOutput[iDstLen] = 0x00;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; return iDstLen;<br>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><img src ="http://www.cppblog.com/winter729/aggbug/131718.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-10-29 10:37 <a href="http://www.cppblog.com/winter729/archive/2010/10/29/131718.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>posix mqueue 使用注意事项</title><link>http://www.cppblog.com/winter729/archive/2010/10/21/130727.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Thu, 21 Oct 2010 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/10/21/130727.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/130727.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/10/21/130727.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/130727.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/130727.html</trackback:ping><description><![CDATA[1,头文件：<br>#include &lt;fcntl.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* For O_* constants */<br>#include &lt;sys/stat.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* For mode constants */<br>#include &lt;mqueue.h&gt;<br><br>2,mq_open 在指定 mqueue 的名字时，必须以 &#8221;/"  开头，并且名字中只能有一个 &#8220;/"<br><br>3,对mqueue的队列位置进行重定向 <br>&nbsp;&nbsp;&nbsp;&nbsp;   <strong>$ mkdir /dev/mqueue<br>
&nbsp;&nbsp;&nbsp; $ mount -t mqueue none /dev/mqueue</strong> <br>4,在编译时要加上 -lrt 选项。<br><br><br><br> <img src ="http://www.cppblog.com/winter729/aggbug/130727.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-10-21 11:31 <a href="http://www.cppblog.com/winter729/archive/2010/10/21/130727.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>文件IO和标准IO的对比</title><link>http://www.cppblog.com/winter729/archive/2010/10/18/130238.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Mon, 18 Oct 2010 02:27:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/10/18/130238.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/130238.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/10/18/130238.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/130238.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/130238.html</trackback:ping><description><![CDATA[<span style="font-weight: bold; color: #0010ff;">文件IO</span>使用文件描述符进行操作。<br>常用函数：<br>open ： 返回打开指定路径文件的描述符<br>read&nbsp; ： 读取描述符指定的文件的内容，没有缓冲<br>write ： 写描述符指定的文件，没有缓冲<br>lseek ：为打开的文件设置偏移值（SEEK_SET; SEEK_CUR ;SEEK_END）<br><br><span style="color: #0010ff; font-weight: bold;">标准IO</span>对流进行操作，即： FILE * <br>（FILE 是个结构体，里面包含了文件描述符和缓冲区的信息）<br>我们常用的stdin,stdout,stderr 类型都是FILE *<br>常用函数：<br>fopen :返回打开指定路径文件的标准IO流：即FILE*<br>fdopen:将指定的文件描述符与标准IO流相关联。<img src="http://www.cppblog.com/CuteSoft_Client/CuteEditor/images/emstar.gif" align="absmiddle" border="0"><br>setbuf: 设置IO流的缓冲大小，设置成NULL即没有缓冲<br>fgetc:&nbsp; 读一个char<br>fputc:&nbsp; 写一个char<br>fgets:&nbsp; 读一行<br>fputs:&nbsp; 写一行<br>fread: 读取指定个数的长度<br>fwrite: 写入指定个数的长度<br>fflush:强制冲洗一个流<br><br>   <img src ="http://www.cppblog.com/winter729/aggbug/130238.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-10-18 10:27 <a href="http://www.cppblog.com/winter729/archive/2010/10/18/130238.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tcpdump 用法</title><link>http://www.cppblog.com/winter729/archive/2010/08/20/124075.html</link><dc:creator>午夜凉饭</dc:creator><author>午夜凉饭</author><pubDate>Fri, 20 Aug 2010 03:06:00 GMT</pubDate><guid>http://www.cppblog.com/winter729/archive/2010/08/20/124075.html</guid><wfw:comment>http://www.cppblog.com/winter729/comments/124075.html</wfw:comment><comments>http://www.cppblog.com/winter729/archive/2010/08/20/124075.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/winter729/comments/commentRss/124075.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/winter729/services/trackbacks/124075.html</trackback:ping><description><![CDATA[第一种是关于类型的关键字，主要包括host，net，port, 例如 host 210.27.48.2，指明
210.27.48.2是一台主机，net 202.0.0.0 指明 202.0.0.0是一个网络地址，port 23
指明端口号是23。如果没有指定类型，缺省的类型是host.<br>
第二种是确定传输方向的关键字，主要包括src , dst ,dst or src, dst and src
,这些关键字指明了传输的方向。举例说明，src 210.27.48.2 ,指明ip包中源地址是210.27.48.2 , dst net
202.0.0.0 指明目的网络地址是202.0.0.0 。如果没有指明方向关键字，则缺省是src or dst关键字。<br>
第三种是协议的关键字，主要包括fddi,ip,arp,rarp,tcp,udp等类型。Fddi指明是在FDDI(分布式光纤数据接口网络)上的特定
的网络协议，实际上它是"ether"的别名，fddi和ether具有类似的源地址和目的地址，所以可以将fddi协议包当作ether的包进行处理和
分析。其他的几个关键字就是指明了监听的包的协议内容。如果没有指定任何协议，则tcpdump将会监听所有协议的信息包。<br>
&nbsp; &nbsp; 除了这三种类型的关键字之外，其他重要的关键字如下：gateway,
broadcast,less,greater,还有三种逻辑运算，取非运算是 'not ' '! ',
与运算是'and','&amp;&amp;';或运算 是'or'
,'││'；这些关键字可以组合起来构成强大的组合条件来满足人们的需要，下面举几个例子来说明。<br>
&nbsp; &nbsp; 普通情况下，直接启动tcpdump将监视第一个网络界面上所有流过的数据包。<br>
# tcpdump <br>
tcpdump: listening on fxp0<br>
11:58:47.873028 202.102.245.40.netbios-ns &gt; 202.102.245.127.netbios-ns: udp 50<br>
11:58:47.974331 0:10:7b:8:3a:56 &gt; 1:80:c2:0:0:0 802.1d ui/C len=43<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0000 0000 0080 0000 1007 cf08 0900 0000<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0e80 0000 902b 4695 0980 8701 0014 0002<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 000f 0000 902b 4695 0008 00<br>
11:58:48.373134 0:0:e8:5b:6d:85 &gt; Broadcast sap e0 ui/C len=97<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ffff 0060 0004 ffff ffff ffff ffff ffff<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0452 ffff ffff 0000 e85b 6d85 4008 0002<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0640 4d41 5354 4552 5f57 4542 0000 0000<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0000 00<br>
使用-i参数指定tcpdump监听的网络界面，这在计算机具有多个网络界面时非常有用，<br>
使用-c参数指定要监听的数据包数量，<br>
使用-w参数指定将监听到的数据包写入文件中保存<br>
&nbsp; &nbsp;A想要截获所有210.27.48.1 的主机收到的和发出的所有的数据包：<br>
#tcpdump host 210.27.48.1 <br>
B想要截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信，使用命令：（在命令行中适用　　　括号时，一定要<br>
#tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3 ) <br>
C如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包，使用命令：<br>
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2<br>
D如果想要获取主机210.27.48.1接收或发出的telnet包，使用如下命令：<br>
#tcpdump tcp port 23 host 210.27.48.1<br>
E 对本机的udp 123 端口进行监视 123 为ntp的服务端口<br>
# tcpdump udp port 123 <br>
&nbsp;&nbsp;<br>
F 系统将只对名为hostname的主机的通信数据包进行监视。主机名可以是本地主机，也可以是网络上的任何一台计算机。下面的命令可以读取主机hostname发送的所有数据： <br>
#tcpdump -i eth0 src host hostname<br>
G 下面的命令可以监视所有送到主机hostname的数据包： <br>
#tcpdump -i eth0 dst host hostname<br>
H&nbsp;&nbsp;我们还可以监视通过指定网关的数据包： <br>
#tcpdump -i eth0 gateway Gatewayname<br>
I 如果你还想监视编址到指定端口的TCP或UDP数据包，那么执行以下命令： <br>
#tcpdump -i eth0 host hostname and port 80<br>
J 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包<br>
，使用命令：<br>
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2<br>
K 想要截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信，使用命令<br>
：（在命令行中适用　　　括号时，一定要<br>
#tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3 )<br>
L 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包，使用命令：<br>
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2<br>
M 如果想要获取主机210.27.48.1接收或发出的telnet包，使用如下命令：<br>
#tcpdump tcp port 23 host 210.27.48.1<br>
第三种是协议的关键字，主要包括fddi,ip ,arp,rarp,tcp,udp等类型<br>
除了这三种类型的关键字之外，其他重要的关键字如下：gateway, broadcast,less,<br>
greater,还有三种逻辑运算，取非运算是 'not ' '! ', 与运算是'and','&amp;&amp;';或运算 是'o<br>
r' ,'||'；<br>
第二种是确定传输方向的关键字，主要包括src , dst ,dst or src, dst and src ,<br>
如果我们只需要列出送到80端口的数据包，用dst port；如果我们只希望看到返回80端口的数据包，用src port。 <br>
#tcpdump &#8211;i eth0 host hostname and dst port 80&nbsp;&nbsp;目的端口是80<br>
或者<br>
#tcpdump &#8211;i eth0 host hostname and src port 80&nbsp;&nbsp;源端口是80&nbsp;&nbsp;一般是提供http的服务的主机<br>
如果条件很多的话&nbsp;&nbsp;要在条件之前加and 或 or 或 not<br>
#tcpdump -i eth0 host ! 211.161.223.70 and ! 211.161.223.71 and dst port 80<br>
如果在ethernet 使用混杂模式 系统的日志将会记录<br>
May&nbsp;&nbsp;7 20:03:46 localhost kernel: eth0: Promiscuous mode enabled.<br>
May&nbsp;&nbsp;7 20:03:46 localhost kernel: device eth0 entered promiscuous mode<br>
May&nbsp;&nbsp;7 20:03:57 localhost kernel: device eth0 left promiscuous mode<br>
tcpdump对截获的数据并没有进行彻底解码，数据包内的大部分内容是使用十六进制的形式直接打印输出的。显然这不利于分析网络故障，通常的解决办法是
先使用带-w参数的tcpdump
截获数据并保存到文件中，然后再使用其他程序进行解码分析。当然也应该定义过滤规则，以避免捕获的数据包填满整个硬盘。<br>
评论摘要：<br>
1，<br>
其实LZ 只说明了过滤语句的用法，没有将很重要另外一个参数说明，也就是说，如果这个参数不设置正确，会导致包数据的丢失！<br>
它就是-s 参数，snaplen, 也就是数据包的截取长度，仔细看man就会明白的！默认截取长度为60个字节，但一般ethernet MTU都是1500字节。所以，要抓取大于60字节的包时，使用默认参数就会导致包数据丢失！<br>
只要使用-s 0就可以按包长，截取数据！<br>
2，<br>
各位有兴趣，我可以多说一点。<br>
LZ所说的这个格式有一个业界标准，称作bpf (Berkeley Packet
Filter)包过滤语言。现在有很多抓包工具支持这个标准。包扩ethereal的capture filter,
注意不是displayfilter, 因为ethereal的display filter 使用了近似于C/C++表达式的另一套自己的表达方式。<br>
其实，如果各位使用过libpcap的，就知道，所有的libpcap都需要snaplen
这个参数设定才能抓到整个的包数据。那如果不熟悉C/C++怎么办?，没关系那也可以结合tcpdump -xls 0
命令行加管道导向到Awk的程序来自己解析IP数据包并分析应用层的数据。如果用tcpdump+Perl的话，更可以经过简单的包数据重构，方便地组成
NetPacket模块能自动识别的包数据，让现成的NetPacket模块自动解析和分析底层的IP和TCP/UDP层数据包。而你则只要懂得gawk
/nawk或Perl就可以简单的自己编程来解析非标的应用层的数据了。注意，这里我并没有使用perl
的libpcap兼容模块，而是直接用tcpdump替代了。这样对Perl模块的要求降得比较低了，如果遇到非标的协议，就是不会C/C++,
没装抓包的perl模块，也可以通过自己编程来解析数剧包了！<br>
3，<br>
还好的是可以通过hex value来查包中的汉字。我是先在linux上边tcpdump出完整的package data，然后呢，将文件down到windows上来用ethereal来做查看的。<br>
我不是很理解你所说的 '要么在服务器端装支持相应编码的代理，然后dump数据。<br>
你说的编码的代理，我觉得这个与整个网页的charset是有关系的。可能是不同的charset,gb2312,unicode或是gbk之类的。很难理解你说的编码的代理是什么东东？<br>
我想ethereal就是没有去分析每个包应该用什么来charset来做显示，所以都以ascii来显示了。所以汉字就显示不出来。<br>
要想ethereal知道使用什么样的charset显示，那么就需要联系其他包里的charset设置来做显示，看来ethereal目前还没这么做，就只是简单的显示ascii。<img src ="http://www.cppblog.com/winter729/aggbug/124075.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/winter729/" target="_blank">午夜凉饭</a> 2010-08-20 11:06 <a href="http://www.cppblog.com/winter729/archive/2010/08/20/124075.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>