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