免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: duanjigang
打印 上一主题 下一主题

源码阅读第一期:axel和wget [复制链接]

论坛徽章:
0
111 [报告]
发表于 2011-10-05 12:21 |只看该作者
貌似,calltree -gb -np -m 这个命令是有局限的。把我带进了test.c中的main()入口函数。如今我遇到其他的几 ...
wangzhen11aaa 发表于 2011-10-04 20:50



    呵呵,找对main入口,多个main和多进程没关系的

论坛徽章:
0
112 [报告]
发表于 2011-10-05 12:23 |只看该作者
如果配置文件里边的参数是分组的怎么办?
举个例子,ipsec-tools的配置文件:
remote anonymous
{
        exc ...
VIP_fuck 发表于 2011-10-04 21:07



    呵呵,没太明白你的意思,分组?啥生意?“怎么办?”嘿嘿,不明白问题在哪 说清楚下,举例最好

论坛徽章:
0
113 [报告]
发表于 2011-10-05 12:33 |只看该作者
弱弱的问一句,tcp.c文件中的int fd = socket( PF_INET, SOCK_DGRAM, IPPROTO_IP );其中这些参数的设置有 ...
ccnufufan 发表于 2011-10-04 21:57



    呵呵,这个帖子
TCP/IP学习与实践[基于原始套接字的rootkit]
http://bbs.chinaunix.net/viewthr ... p;extra=&page=1
是我06年学习网络编程时发的,你可以参考下,讲socket,tcp/ftp/rawsocket等
关于socket, connect,bind, accept listen setsockopt, select, epoll,阻塞和非阻塞
这些API的用法和概念,其实有很多方法途径能了解的:(1)unix网络编程那本大作(很可惜我至今未拜读)(2):google上的一些examples (3)man手册
另外一些中文帖子也不错的。(以上1,2,3排序不分先后喔)

论坛徽章:
0
114 [报告]
发表于 2011-10-05 13:03 |只看该作者
貌似,calltree -gb -np -m 这个命令是有局限的。把我带进了test.c中的main()入口函数。如今我遇到其他的几 ...
wangzhen11aaa 发表于 2011-10-04 20:50



    我刚打开wget的代码看了下
两个main函数
一个在test.c中
一个在main.c中
显然,我跟根据文件名字很容易知道main.c中的main是wget的入口函数。(呵呵。这个比axel好多了,axel把main写在text.c中,而不在axel.c中)

而且还有一个方法能验证。
当你

  1. ./configure
  2. make
复制代码
之后,进入src目录。能看到wget这一个二进制文件

  1. rm -fr wget
复制代码
之后,再次make
就能看到链接器的语句了

  1. gcc  -O2 -Wall   -o wget cmpt.o connect.o convert.o cookies.o ftp.o css.o css-url.o ftp-basic.o ftp-ls.o hash.o host.o html-parse.o html-url.o http.o init.o log.o main.o netrc.o progress.o ptimer.o recur.o res.o retr.o spider.o url.o utils.o exits.o build_info.o iri.o version.o ftp-opie.o ../lib/libgnu.a -lidn -lrt
复制代码
wget再次生成,很显然,生成wget时并未用test.o,而是main.o,因此,wget肯定是用了main.c中的main作为入口的。嘿嘿

论坛徽章:
0
115 [报告]
发表于 2011-10-05 13:54 |只看该作者
回复 115# duanjigang
呵呵,早晚知道那几个main()是作啥的!

论坛徽章:
1
双子座
日期:2013-11-06 17:18:01
116 [报告]
发表于 2011-10-05 17:13 |只看该作者
本帖最后由 duanjigang 于 2011-10-06 10:30 编辑

回复 68# duanjigang
  1. if( *conn->conf->http_proxy == 0 )
  2.         {
  3.                 proxy = NULL;
  4.         }
  5.         else if( *conn->conf->no_proxy != 0 )    //no_proxy[]数组第一个不是'\0'
  6.         {
  7.                 for( i = 0; ; i ++ )
  8.                         if( conn->conf->no_proxy[i] == 0 )  //判断数组元素如果是'\0'则执行下面内容
  9.                         {
  10.                                 if( strstr( conn->host, host ) != NULL )
  11.                                         proxy = NULL;
  12.                                 host = &conn->conf->no_proxy[i+1];
  13.                                 if( conn->conf->no_proxy[i+1] == 0 )
  14.                                 break;
  15.                         }        
  16.         }
复制代码
为什么no_proxy是等于0,好像应该是!=吧,no_proxy[]不为空数组
char no_proxy[MAX_STRING]; //这个字符数组里包含了配置文件中no_proxy所有url吗?那每个url在no_proxy[]数组里怎样分隔开的?还是每个数组只有一个url?

##################
no_proxy=en.newhua.com,bbs.chinaunix.com
将来conn->conf->no_proxy[]数组内容是{e,n,.,n,e,w,h,u,a,.,c...............\0}吗
这里没看懂.

论坛徽章:
0
117 [报告]
发表于 2011-10-05 20:28 |只看该作者
本帖最后由 duanjigang 于 2011-10-05 20:29 编辑
回复  duanjigang 为什么no_proxy是等于0,好像应该是!=吧,no_proxy[]不为空数组
char no_proxy[MAX_STRING ...
seufy88 发表于 2011-10-05 17:13



    哪里有no_proxy=0?呵呵,第一行写的是 http_proxy==0的

是这样的,如果你的配置文件中写

  1. no_proxy=www.126.com   bbs.chinaunix.net test.com
复制代码
no_proxy是包含了所有不用proxy的URL
axel会把它加工成用逗号分割的,conn->conf->no_proxy是这样

  1. www.126.com,bbs.chinaunix.net,test.com
复制代码

论坛徽章:
1
双子座
日期:2013-11-06 17:18:01
118 [报告]
发表于 2011-10-05 21:31 |只看该作者
本帖最后由 duanjigang 于 2011-10-06 10:46 编辑

回复 118# duanjigang

哦,我说的是第五行:wink:
假设no_proxy被axel处理后内容为:
www.126.com,bbs.chinaunix.net,test.com\0
conn->host[]内容为www.126.com\0

第5行开始,判断no_proxy[0]是否为'\0',如果不是,执行下面内容
第8行中紧接着循环体中判断no_proxy,可是发现循环下来除了结尾其他的都不满足第8行的条件,所以有点困惑
  1. if(conn->conf->no_proxy[i] == 0 )
复制代码

论坛徽章:
0
119 [报告]
发表于 2011-10-05 22:02 |只看该作者
67 /* Data type for reentrant functions.  */ 此用来返回函数值,这是在main函数中的一个数据结构。
68 struct _getopt_data
69 {
70   /* These have exactly the same meaning as the corresponding global
71      variables, except that they are used for the reentrant
72      versions of getopt.  */
73   int optind;  /*选项的索引 */
74   int opterr; /*是否打印出错误*/
75   int optopt;  /*getopt返回
76   char *optarg; /*如果返回值有参数那么指向参数*/
77
78   /* Internal members.  */
79
80   /* True if the internal members have been initialized.  */
81   int __initialized;
82
83   /* The next char to be scanned in the option-element
84      in which the last option character we returned was found.
85      This allows us to pick up the scan where we left off.
86
87      If this is zero, or a null string, it means resume the scan
88      by advancing to the next ARGV-element.  */
89   char *__nextchar;  /*如果此值是0或者为空字符,那么意味着恢复查看到下个argv-字符*/
90
91   /* See __ord above.  */
92   enum __ord __ordering;  /*
93
94   /* If the POSIXLY_CORRECT environment variable is set
95      or getopt was called.  */
96   int __posixly_correct; /*如果posixly_correct环境变量被设置为1,或者getopt被调用*/
97
98
99   /* Handle permutation of arguments.  */
100
101   /* Describe the part of ARGV that contains non-options that have
102      been skipped.  `first_nonopt' is the index in ARGV of the first
103      of them; `last_nonopt' is the index after the last of them.  */
104
105   int __first_nonopt;  /*描述部分还有空选项的被跳过的argv,first_nonopt是它们第一个argv的索引值,last_nonopt在它们最后面的那个索引值之后。
106   int __last_nonopt;
107
108 #if defined _LIBC && defined USE_NONOPTION_FLAGS
109   int __nonoption_flags_max_len;
110   int __nonoption_flags_len;
111 #endif
112 };
翻译:
/* Describe how to deal with options that follow non-option ARGV-elements.
34 /*描述怎么处理跟在空选项后面的选项*/
35    If the caller did not specify anything,
36    the default is REQUIRE_ORDER if the environment variable
37    POSIXLY_CORRECT is defined, PERMUTE otherwise.
38 /*如果调用者没有说明,那么默认的就是(REQUIRE_ORDER),当环境变量POSIXLY_CORRECT被定义,否则为PERMUTE*/
39    REQUIRE_ORDER means don't recognize them as options;
40    stop option processing when the first non-option is seen.
41    This is what Unix does.
42    This mode of operation is selected by either setting the environment
43    variable POSIXLY_CORRECT, or using `+' as the first character
44    of the list of option characters, or by calling getopt.
45 /*REQUIRE_ORDER 意味着不把它们当作选项,停止选项处理,当第一个空选项被发现,这是unix所作的。 这种处理方式被选择,当环境变量POSIX_CORRECT或者用‘+’字符当作选项字符表的第一个,或者调用getop.
46    PERMUTE is the default.  We permute the contents of ARGV as we
47    scan, so that eventually all the non-options are at the end.
48    This allows options to be given in any order, even with programs
49    that were not written to expect this.
50 /*PERMUTE是默认的。我们从新排序整个被扫描的argv,直到所有最后空选项都在末尾出现。这允许选项以任何顺序出现,甚至程序都没有想到过的方式。
51    RETURN_IN_ORDER is an option available to programs that were
52    written to expect options and other ARGV-elements in any order
53    and that care about the ordering of the two.  We describe each
54    non-option ARGV-element as if it were the argument of an option
55    with character code 1.  Using `-' as the first character of the
56    list of option characters selects this mode of operation.
57 /*RETURN_IN_ORDER是一个可用的选项来使程序期望选项和其他的argv元素的任何顺序,并且关心它们两个的顺序。我们描述每一个空选项argv并且把它当作含有字符1的一个选项的参数。用'-'作为选项清单的第一个选项来选择这种操作方式。
58    The special argument `--' forces an end of option-scanning regardless
59    of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
60    `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
61
62 enum __ord
63   {
64     REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
65   };

论坛徽章:
0
120 [报告]
发表于 2011-10-06 10:48 |只看该作者
回复  duanjigang

哦,我说的是第五行
假设no_proxy被axel处理后内容为:
,bbs.chinaunix.net,t ...
seufy88 发表于 2011-10-05 21:31



    不好意思,我看到你那个问题怎么都是斜体字,就想编辑下。。不想到数据弄丢了。。
对不起啊,有空的话,你把那个帖子重新编辑下,补充上完整内容,实在不好意思
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP