ping源代码 [英] ping source code

查看:181
本文介绍了ping源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读ping的原始源代码以获得一些见解

并且被不寻常的代码混淆。


整个列表可在:
http://www.ping127001.com/pingpage/ping.html


#include #include #include

#include #include #include #include

#include #include #include #include #include


这是什么意思?这就是#include'的所有内容。


main(argc,argv)

char * argv [];

{


这就是主要功能的开始。这是合法的吗?


有些网络相关的结构我不知道它们来自哪里因为缺少任何可识别的
#包含文件。

代码组织良好,注释良好。据我所知,这个

程序是从1982年开始的。只是为了好玩,我通过gcc运行它和/ b $ b产生了很多错误,其中很多都是由于缺乏

合法#includes。这是什么意思呢?不应该是着名的

Ping代码用gcc编译吗?


编译错误:


pg.c :2:错误:在我之前解析错误

pg.c:24:10:#include期望FILENAME或< FILENAME>

pg.c:25:10:#include期望FILENAME或< FILENAME>

pg.c:26:10:#include期望FILENAME或者< FILENAME>

pg.c:在函数`main''中:

pg.c:72:错误:'from''isn''的存储大小知道

pg.c:82:错误:`SO_DEBUG''未声明(首次使用此函数)

pg.c:82:错误:(每个未声明的标识符仅报告一次

pg.c:82:错误:对于它出现的每个函数。)

pg.c:85:错误:`SO_DONTROUTE''未声明(首次使用此函数)

pg.c:104:错误:将`sizeof''应用于不完整类型无效
pg.c:105:错误:解除引用指向不完整类型的指针

pg.c:105:错误:`AF_INET''未声明(在此函数中首次使用)

pg.c:106:错误:解除引用指针到不完整的类型

pg.c:107:错误:取消引用指向不完整类型的指针

pg.c:111:警告:赋值使整数指针不带

cast

pg.c:113:错误:解除指向不完整类型的指针

pg.c:11 3:错误:取消引用指向不完整类型的指针

pg.c:114:错误:解除指向不完整类型的指针

pg.c:114:错误:`caddr_t''未声明(在此函数中首次使用)

pg.c:114:错误:解除引用指向不完整类型的指针

pg.c:114:错误:取消引用指向不完整类型的指针

pg.c:115:错误:解除指向不完整类型的指针

pg.c:127:错误:`stderr''未声明(首次在此函数中使用)

pg.c:130:错误:将`sizeof''应用于不完整类型无效
pg.c:141:警告:赋值使整数指针不带< br $>
cast

pg.c:141:错误:'NULL''未声明(首次使用此功能)

pg.c:146:错误:`SOCK_RAW''未声明(在此函数中首次使用)

pg.c:146:错误:取消引用指向不完整类型的指针

pg.c:153:错误:'SOL_SOCKET''未声明(首次使用此功能)

pg.c:161:错误:取消引用指向不完整类型的指针

pg.c:163:错误:解除指向不完整类型的指针

pg.c:167:错误:`stdout''未声明(首次使用此功能)

pg.c:169:错误:`SIGINT''未声明(首次使用此功能)

pg.c:170:错误:`SIGALRM''未声明(在此函数中首次使用)

pg.c:180:错误:`packet''未声明(首次在此函数中使用)

pg.c:183:错误:'timeout'的存储大小'不知道

pg.c:195:错误:`EINTR''未声明(首次使用)在这个函数中)

pg.c:在函数`catcher'':

pg.c:232:错误:`SIGALRM''未声明(首次使用此函数) )

pg.c:函数`pinger'':

pg.c:248:错误:outpack之前的语法错误

pg.c:249:错误:`outpack''未声明(在此函数中首次使用)

pg.c:252:错误:''*'之前的语法错误令牌

pg.c:254:错误:解除指向不完整类型的指针

pg.c:254:错误:`ICMP_ECHO''未声明(首次在此函数中使用)

pg.c:255:错误:解除指向不完整类型的指针

pg.c:256:错误:解除指向不完整类型的指针

pg.c:257:错误:解除引用不完整类型的指针

pg.c:258:错误:解除指向不完整类型的指针

pg.c:265:错误: `iicmp_cksum''未声明(在此函数中首次使用)

pg.c:268:错误:将`sizeof''应用于不完整类型无效

pg.c :268:错误:''之前解析错误''''令牌

pg.c:274:错误:`stdout''未声明(首次使用此功能)

pg.c:顶层:

pg.c:276:错误:在if之前解析错误

pg.c:278:警告:参数名称(功能中没有类型)

声明

pg.c:278:警告:数据定义有没有类型或存储类

pg.c:279:错误:在''}''令牌之前解析错误

pg.c:在函数`pr_pack'':

pg.c:332:错误:`packet''未声明(首次使用此函数)

pg.c:334:错误:'tv'的存储大小不知道

pg.c:338:错误:解除指向不完整类型的指针

pg.c:338:错误:解除指向不完整类型的指针

pg.c:342:错误:解除指向不完整类型的指针

pg.c:343:错误:`ICMP_MINLEN''未声明(首次使用此功能)

pg.c:346:错误:解除指向不完整类型的指针

pg.c:351:错误:解除指向不完整类型的指针

pg.c: 351:错误:`ICMP_ECHOREPLY''未声明(首次使用此

函数)

pg.c:353:错误:解除指向不完整类型的指针

pg.c:354:错误:取消引用指向不完整类型的指针

pg.c:354:错误:dereferenci指向不完整类型的指针

pg.c:354:错误:解除指向不完整类型的指针

pg.c:362:错误:解除指向不完整类型的指针

pg.c:366:错误:解除指向不完整类型的指针

pg.c:379:错误:解除指向不完整类型的指针

pg.c :380:错误:取消引用指向不完整类型的指针

pg.c:387:错误:`stdout''未声明(在此函数中首次使用)

pg.c:顶级:

pg.c:401:错误:在u_short之前解析错误

pg.c:401:警告:数据定义没有类型或存储class

pg.c:403:错误:在''''令牌之前解析错误

pg.c:405:错误:在''*'之前解析错误令牌

pg.c:405:错误:初始化元素不是常数

pg.c:405:警告:数据定义没有类型或存储类

pg.c:406:错误:在回答之前解析错误

pg.c:406:警告:d ata定义没有类型或存储类

pg.c:407:错误:寄存器名称未指定为sum'

pg.c:415:错误:解析在while之前的错误

pg.c:424:错误:在''*''令牌之前解析错误

pg.c:431:错误:重新定义`总和''

pg.c:407:错误:`sum''先前在这里定义

pg.c:431:错误:初始化元素不是常数

pg.c:431:警告:数据定义没有类型或存储类

pg.c:432:错误:在''+ =''令牌之前解析错误

pg.c:433:错误:初始化元素不是常数

pg.c:433:警告:数据定义没有类型或存储类

pg.c:434:错误:在返回之前解析错误

pg.c:在函数`tvsub''中:

pg.c:447:错误:取消引用指向不完整类型的指针

pg.c:447:错误:解除指向不完整类型的指针

pg.c:448:错误:解除引用指向不完整类型的指针

pg.c:449:错误:解除引用指向不完整类型的指针

pg.c:451:错误:解除指向不完整类型的指针

pg.c:451:错误:解除指向不完整类型的指针

pg.c:在函数`finish''中:

pg.c:466:错误:`stdout''未声明(首次使用此函数)

pg.c:顶层:

pg.c:42:错误:存储大小为` tz''不知道

pg.c:44:错误:'whereto'的存储大小是不可知的

I was reading through original source code of ping for some insight
and was confused by unusual code.

Entire listing available at:
http://www.ping127001.com/pingpage/ping.html

#include #include #include
#include #include #include #include
#include #include #include #include #include

What does this mean? That is all of the #include''s there are.

main(argc, argv)
char *argv[];
{

That is how the main function starts. Is that legal?

There are structs that are network related that I don''t know where
they come from because of the lack of any recongnizable #include file.
The code is well organized and commented. I understand that this
program is from 1982. Just for fun, I ran it through gcc and it
generated a lot of errors, many of which are due to the lack of
legitimate #includes. What does this all mean? Shouldn''t the famous
Ping code compile with gcc?

Compile errors:

pg.c:2: error: parse error before "I"
pg.c:24:10: #include expects "FILENAME" or <FILENAME>
pg.c:25:10: #include expects "FILENAME" or <FILENAME>
pg.c:26:10: #include expects "FILENAME" or <FILENAME>
pg.c: In function `main'':
pg.c:72: error: storage size of `from'' isn''t known
pg.c:82: error: `SO_DEBUG'' undeclared (first use in this function)
pg.c:82: error: (Each undeclared identifier is reported only once
pg.c:82: error: for each function it appears in.)
pg.c:85: error: `SO_DONTROUTE'' undeclared (first use in this function)
pg.c:104: error: invalid application of `sizeof'' to an incomplete type
pg.c:105: error: dereferencing pointer to incomplete type
pg.c:105: error: `AF_INET'' undeclared (first use in this function)
pg.c:106: error: dereferencing pointer to incomplete type
pg.c:107: error: dereferencing pointer to incomplete type
pg.c:111: warning: assignment makes pointer from integer without a
cast
pg.c:113: error: dereferencing pointer to incomplete type
pg.c:113: error: dereferencing pointer to incomplete type
pg.c:114: error: dereferencing pointer to incomplete type
pg.c:114: error: `caddr_t'' undeclared (first use in this function)
pg.c:114: error: dereferencing pointer to incomplete type
pg.c:114: error: dereferencing pointer to incomplete type
pg.c:115: error: dereferencing pointer to incomplete type
pg.c:127: error: `stderr'' undeclared (first use in this function)
pg.c:130: error: invalid application of `sizeof'' to an incomplete type
pg.c:141: warning: assignment makes pointer from integer without a
cast
pg.c:141: error: `NULL'' undeclared (first use in this function)
pg.c:146: error: `SOCK_RAW'' undeclared (first use in this function)
pg.c:146: error: dereferencing pointer to incomplete type
pg.c:153: error: `SOL_SOCKET'' undeclared (first use in this function)
pg.c:161: error: dereferencing pointer to incomplete type
pg.c:163: error: dereferencing pointer to incomplete type
pg.c:167: error: `stdout'' undeclared (first use in this function)
pg.c:169: error: `SIGINT'' undeclared (first use in this function)
pg.c:170: error: `SIGALRM'' undeclared (first use in this function)
pg.c:180: error: `packet'' undeclared (first use in this function)
pg.c:183: error: storage size of `timeout'' isn''t known
pg.c:195: error: `EINTR'' undeclared (first use in this function)
pg.c: In function `catcher'':
pg.c:232: error: `SIGALRM'' undeclared (first use in this function)
pg.c: In function `pinger'':
pg.c:248: error: syntax error before "outpack"
pg.c:249: error: `outpack'' undeclared (first use in this function)
pg.c:252: error: syntax error before ''*'' token
pg.c:254: error: dereferencing pointer to incomplete type
pg.c:254: error: `ICMP_ECHO'' undeclared (first use in this function)
pg.c:255: error: dereferencing pointer to incomplete type
pg.c:256: error: dereferencing pointer to incomplete type
pg.c:257: error: dereferencing pointer to incomplete type
pg.c:258: error: dereferencing pointer to incomplete type
pg.c:265: error: `iicmp_cksum'' undeclared (first use in this function)
pg.c:268: error: invalid application of `sizeof'' to an incomplete type
pg.c:268: error: parse error before '';'' token
pg.c:274: error: `stdout'' undeclared (first use in this function)
pg.c: At top level:
pg.c:276: error: parse error before "if"
pg.c:278: warning: parameter names (without types) in function
declaration
pg.c:278: warning: data definition has no type or storage class
pg.c:279: error: parse error before ''}'' token
pg.c: In function `pr_pack'':
pg.c:332: error: `packet'' undeclared (first use in this function)
pg.c:334: error: storage size of `tv'' isn''t known
pg.c:338: error: dereferencing pointer to incomplete type
pg.c:338: error: dereferencing pointer to incomplete type
pg.c:342: error: dereferencing pointer to incomplete type
pg.c:343: error: `ICMP_MINLEN'' undeclared (first use in this function)
pg.c:346: error: dereferencing pointer to incomplete type
pg.c:351: error: dereferencing pointer to incomplete type
pg.c:351: error: `ICMP_ECHOREPLY'' undeclared (first use in this
function)
pg.c:353: error: dereferencing pointer to incomplete type
pg.c:354: error: dereferencing pointer to incomplete type
pg.c:354: error: dereferencing pointer to incomplete type
pg.c:354: error: dereferencing pointer to incomplete type
pg.c:362: error: dereferencing pointer to incomplete type
pg.c:366: error: dereferencing pointer to incomplete type
pg.c:379: error: dereferencing pointer to incomplete type
pg.c:380: error: dereferencing pointer to incomplete type
pg.c:387: error: `stdout'' undeclared (first use in this function)
pg.c: At top level:
pg.c:401: error: parse error before "u_short"
pg.c:401: warning: data definition has no type or storage class
pg.c:403: error: parse error before ''{'' token
pg.c:405: error: parse error before ''*'' token
pg.c:405: error: initializer element is not constant
pg.c:405: warning: data definition has no type or storage class
pg.c:406: error: parse error before "answer"
pg.c:406: warning: data definition has no type or storage class
pg.c:407: error: register name not specified for `sum''
pg.c:415: error: parse error before "while"
pg.c:424: error: parse error before ''*'' token
pg.c:431: error: redefinition of `sum''
pg.c:407: error: `sum'' previously defined here
pg.c:431: error: initializer element is not constant
pg.c:431: warning: data definition has no type or storage class
pg.c:432: error: parse error before ''+='' token
pg.c:433: error: initializer element is not constant
pg.c:433: warning: data definition has no type or storage class
pg.c:434: error: parse error before "return"
pg.c: In function `tvsub'':
pg.c:447: error: dereferencing pointer to incomplete type
pg.c:447: error: dereferencing pointer to incomplete type
pg.c:448: error: dereferencing pointer to incomplete type
pg.c:449: error: dereferencing pointer to incomplete type
pg.c:451: error: dereferencing pointer to incomplete type
pg.c:451: error: dereferencing pointer to incomplete type
pg.c: In function `finish'':
pg.c:466: error: `stdout'' undeclared (first use in this function)
pg.c: At top level:
pg.c:42: error: storage size of `tz'' isn''t known
pg.c:44: error: storage size of `whereto'' isn''t known

推荐答案

wana< io ***** @ yahoo.com>潦草地写了下面的内容:
wana <io*****@yahoo.com> scribbled the following:
我正在阅读ping的原始源代码以获得一些见解
并且被不寻常的代码搞糊涂了。
整个列表可在以下网址找到:
http:// www .ping127001.com / pingpage / ping.html
#include #include #include
#include #include #include #include
#include #include #include #include #include
这是什么意思?这就是#include'的所有内容。


到底是什么?我根本无法理解这意味着什么。要么它是非标准方言,要么是非标准方言或源代码被破坏。

main(argc,argv)
char * argv [];
{
这就是主要功能的开始。这合法吗?


过去不再是。这是一种预先标准的K& R风格。它仍然被一些编译器接受。

有些网络相关的结构我不知道它们来自哪里因为它们来自缺少任何可识别的#include文件。
代码组织良好,注释良好。我知道这个
程序是从1982年开始的。只是为了好玩,我通过gcc运行它并且它产生了很多错误,其中很多是由于缺少合法的#includes 。这是什么意思呢?难道不应该用gcc编译着名的Ping代码吗?
I was reading through original source code of ping for some insight
and was confused by unusual code. Entire listing available at:
http://www.ping127001.com/pingpage/ping.html #include #include #include
#include #include #include #include
#include #include #include #include #include What does this mean? That is all of the #include''s there are.
What the heck? I can''t fathom out at all what that means. Either it is
a non-standard dialect or the source code is broken.
main(argc, argv)
char *argv[];
{ That is how the main function starts. Is that legal?
It used to be, not any more. That''s a pre-standard K&R style. It''s
still accepted by some compilers.
There are structs that are network related that I don''t know where
they come from because of the lack of any recongnizable #include file.
The code is well organized and commented. I understand that this
program is from 1982. Just for fun, I ran it through gcc and it
generated a lot of errors, many of which are due to the lack of
legitimate #includes. What does this all mean? Shouldn''t the famous
Ping code compile with gcc?




不一定。 C从1982年开始发生了很大变化.gcc可能已经放弃了对某些过时功能的支持。


-

/ - - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \

\\ \\ - http://www.helsinki.fi/~palaste - -------------------规则! -------- /

冰淇淋销售不知何故导致溺水:两者都发生在夏季。

- Antti Voipio& Arto Wikla



Not necessarily. C has changed a lot from 1982. gcc might have
abandoned support for some obsolete features.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Ice cream sales somehow cause drownings: both happen in summer."
- Antti Voipio & Arto Wikla


Joona I Palaste< pa ***** @ cc.helsinki.fi>潦草地写道:
Joona I Palaste <pa*****@cc.helsinki.fi> scribbled the following:
wana< io ***** @ yahoo.com>潦草地写了下面的内容:
wana <io*****@yahoo.com> scribbled the following:
我正在阅读ping的原始源代码以获得一些见解
并且被不寻常的代码搞糊涂了。
整个列表可在以下网址找到:
http:// www .ping127001.com / pingpage / ping.html
#include #include #include
#include #include #include #include
#include #include #include #include #include
这是什么意思?这就是#include'的所有内容。
I was reading through original source code of ping for some insight
and was confused by unusual code. Entire listing available at:
http://www.ping127001.com/pingpage/ping.html #include #include #include
#include #include #include #include
#include #include #include #include #include What does this mean? That is all of the #include''s there are.


到底是什么?我根本无法理解这意味着什么。要么它是非标准的方言,要么是源代码被破坏。

What the heck? I can''t fathom out at all what that means. Either it is
a non-standard dialect or the source code is broken.




*现在*我明白了。它实际上是读取

#include< foo.h>

#include< bar.h>

#include< quux.h> ;

#include< quuux.h>

(用适当的名字替换愚蠢的名字)

但因为托管网络服务器的白痴正在为页面提供HTML / b $ HTML而不是纯文本,Web浏览器正在过滤标题

名称,认为它们是非标准的HMTL标签。 />

-

/ - Joona Palaste(pa*****@cc.helsinki.fi)----------- - 芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /

我们怎样才能用性来获得我们想要的东西?性是我们想要的。

- Frasier Crane博士



*NOW* I understand. It actually reads
#include <foo.h>
#include <bar.h>
#include <quux.h>
#include <quuux.h>
(replace the silly names with proper ones)
but because the idiot hosting the web server is serving the page as
HTML instead of plain text, the web browser is filtering the header
names away, thinking they''re non-standard HMTL tags.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane


" wana" < IO ***** @ yahoo.com>在消息中写道

news:bf ************************** @ posting.google.c om ...
"wana" <io*****@yahoo.com> wrote in message
news:bf**************************@posting.google.c om...
我正在阅读ping的原始源代码以获得一些见解
并且被不寻常的代码混淆。

整个列表可从以下网址获得:
http://www.ping127001.com/pingpage/ping.html < #include #include #include #include
#include #include #include #include
#include #include #include #include #include

这是什么意思?这就是#include'的所有内容。


这意味着''ping.html''文件不是一个正确的
格式的HTML文件。试试你的浏览器'''查看源''

功能并从那里复制/粘贴代码。

main(argc,argv)
char * argv [];

这就是主要功能的开始。这合法吗?


这不是标准C.它是''旧式''功能标题。

标准表格是:


int main(int argc,char * argv [])

有些网络相关的结构我不知道它们来自哪里因为缺少任何可识别的#include文件。


见上文#includes。但请注意,任何网络

问题都将特定于平台,因此在这里偏离主题。

代码组织良好且评论良好。我知道这个
程序是从1982年开始的。


是的,风格是''旧'。

只是为了好玩,我跑了它通过gcc和它产生了很多错误,其中很多是由于缺乏合法的#includes。



然后你需要修复#includes,并忽略任何其他消息

,它们非常可能是第一个错误消息的工件。

这一切意味着什么?难道不应该用gcc编译着名的Ping代码吗?
I was reading through original source code of ping for some insight
and was confused by unusual code.

Entire listing available at:
http://www.ping127001.com/pingpage/ping.html

#include #include #include
#include #include #include #include
#include #include #include #include #include

What does this mean? That is all of the #include''s there are.
It means that the ''ping.html'' file is not a properly
formatted HTML file. Try your browser''s ''view source''
feature and copy/paste the code from there.

main(argc, argv)
char *argv[];
{

That is how the main function starts. Is that legal?
It''s not standard C. It''s the ''old style'' function header.
Standard form is:

int main(int argc, char *argv[])

There are structs that are network related that I don''t know where
they come from because of the lack of any recongnizable #include file.
See above about the #includes. But note that any networking
issues will will platform-specific, thus off-topic here.
The code is well organized and commented. I understand that this
program is from 1982.
Yes, the style is ''old''.
Just for fun, I ran it through gcc and it
generated a lot of errors, many of which are due to the lack of
legitimate #includes.

Then you need to fix the #includes, and disregard any other messages
which are very likly an artifact of the first error messages.
What does this all mean? Shouldn''t the famous
Ping code compile with gcc?




只有那些非标准的标题(以及它们的图书馆是
)参考)提供并与gcc兼容。


-Mike



Only if those nonstandard headers (and the libraries they
refer to) are provided and are compatible with gcc.

-Mike


这篇关于ping源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆