473,748 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ping source code

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
Nov 14 '05 #1
17 18203
wana <io*****@yahoo. com> scribbled the following:
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?


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

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Ice cream sales somehow cause drownings: both happen in summer."
- Antti Voipio & Arto Wikla
Nov 14 '05 #2
Joona I Palaste <pa*****@cc.hel sinki.fi> scribbled the following:
wana <io*****@yahoo. com> scribbled the following:
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.


*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.hel sinki.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
Nov 14 '05 #3
"wana" <io*****@yahoo. com> wrote in message
news:bf******** *************** ***@posting.goo gle.com...
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?


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

-Mike
Nov 14 '05 #4
wana <io*****@yahoo. com> wrote:
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.
That's simply broken code. Looks as if the required names of files
to be included are simply missing.
main(argc, argv)
char *argv[];
{ That is how the main function starts. Is that legal?
Yes, that's very old code (pre-C89) when C still used a different
method to declare function arguments. But modern compilers still
accept it, so it's not really a problem.
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.
That's highly likely. If you want to know where they come from ask
in e.g. comp.unix.progr ammer (or try to figure it out by yourself
by reading the man pages;-)
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?


No, definitely not without the missing files to be included.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #5
In article <bf************ **************@ posting.google. com>,
wana <io*****@yahoo. com> wrote:
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.
Without going to the URL you posted, this looks like a poor HTMLization
of source code, where the <> in `#include <foo.h>' get treated as tags
(and, since the browser doesn't recognize them, silently ignored).

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

That is how the main function starts. Is that legal?
Yes, but it's outdated.
In K&R C, this was how arguments were declared: names only in the argument
list, and types (defaulting to int if not specified) given between the
function name/argument list and the beginning of the function body.

Except for prototype-based type checking if you call a function after
it's been declared like this, this declaration is equivalent to:
--------
int main(int argc, char *argv[])
--------
which is the preferred form for newly written code. C90 still allows
the older type of declaration; I'm not sure about C99 - implicit int is
gone, but I'm not sure (and don't have a strong enough desire to know
to actually look it up) whether
--------
int main(argc,argv)
int argc;
char *argv[];
{
/*function body here*/
}
--------
is still allowed.

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.
If you dig into the HTML source, I'd expect you'll find the names of the
headers (see above). Most of them are probably unixisms rather than ones
defined by the C language, so if you have questions about them you'd be
likely to get better answers from comp.unix.progr ammer .
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?


Possibly.

For one thing, what your browser is showing you is probably a mangled
version, not the original code. Also, the language has changed somewhat
since 1982, so a lot of what's in the code is no longer considered
good style, and it's quite possible that some of it is no longer legal.
(People who have worked with both K&R C and ANSI/ISO C will be better
able to comment on the differences.)
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca
More and more often I wish I didn't know anything about the Internet so
things like this wouldn't disturb me so much.
--Steve VanDevender in the scary devil monastery
Nov 14 '05 #6
wana wrote:

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.

[...]

Someone called a text file ".html". Look at the source to the page:

==========
[...]
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
[...]
==========

The brackets used by C are being misinterpreted by the browser as HTML
markups, due to the ".html" extension.

Ignore the browser's representation, view the source, and copy-paste that
instead.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Nov 14 '05 #7
Joona I Palaste wrote:
[...]
*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.


Don't blame "the idiot hosting the web server", blame "the idiot who
decided to use a '.html' extension on a plain text file". It's your
browser "filtering the header names away", not the server, and it's
doing it because it was told to do so.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+

Nov 14 '05 #8
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

wana wrote:
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 [snip] 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?


Yes and no.

The late Mike Muus wrote ping for the original BSD sockets implementation, and
the source you found (a secondhand version, to be sure) isn't likely to be
compatable to the library implementations on your much more current system.
Assuming that you take the time to update the constants and syscalls to your
system's requirements, gcc should be able to compile the K&R C that Mike's
code is written in. It should even run.

If you want to read Mike's "The Story of the Ping program" and retrieve the
shar (shell archive - a unix shell script that self-unpacks the source code,
make files, and man pages), take a look at http://ftp.arl.mil/~mike/ping.html

I had the pleasure of having a short conversation with Mike a year or so
before he passed away.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBSieHagV FX4UWr64RAkEMAJ 9diePJA6uWGGfYt exdjNYGWet4PACc CrUK
WbxEhW0m7s2xfdg NREwXomE=
=iZeK
-----END PGP SIGNATURE-----
Nov 14 '05 #9
Jens--

ping

--Jens
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8406
by: Sean Cody | last post by:
Does anyone know of an ping module that will work with Windows? I'm currently using os.popen("ping -n1 host") but it's terribly slow when using it a few hundred times. After enumerating my domain of machines I'm trying to ping them to determine if they are active before connecting to them via WMI (which takes forever to timeout). --
8
4373
by: DCK | last post by:
Hello :) Into group-archive i found most e-mails, which touches PINGing. In my work i've used TELNET for testing if host is operational. Sometimes, for unknown reasons, workstation doesn't respond for PINGing. But in WinNT network, all hosts has a nbsession listening on port 139. I always use this script instead PING command (hope, will be usefull for someone :) ):
3
2265
by: Jason Rodman | last post by:
I have downloaded every example on how to create a ping utility in .Net in both VB and C#, but have been disappointed with the results. I have YET to find an example that returns consistent results that are even close the the actual ping command line utility. For example: If i would ping the same server over and over, some pings would come back in 0 milliseconds, others would come back in 15, but never in between. It would always jump...
0
1392
by: krisan | last post by:
Hi, i am writing a program for ping operation which supports both Ipv4 and IpV6 ..first i wrote for both of them individually , but i am unable to mix them such that they support both the versions ... i would be very thankful if anyone could come out with a complete program .. Ipv6 prog --------- #include<stdio.h> #include<winsock2.h>
0
7782
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info: http://support.microsoft.com/default.aspx?scid=kb;en-us;170591 ). The problem I have is in order to perform a discovery/ping of an entire subnet (192.168.1.* for instance) I have to do a FOR loop to itterate through all of the addresses. That it seems...
7
7262
by: luvwknd | last post by:
Hi all, I am attempting to utilize MS's article I.D. #828993 found at: http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B828993 In an effort to create a GUI Ping utility that ultimately will show me via a green indicator if a system is pingable and a red indicator if a system is not pingable. In addition I want to be able to ping a range of addresses at one time and have the program return my indicators.
5
7405
by: Sonda | last post by:
how to ping ip address from c language ?
6
3459
by: Dave Marden | last post by:
I currently use this routine in vbscript to ping computers and get the status of ping to determine whether to try to backup a machine, I am trying to change it to work with vb2003.net I am wondering if anyone has a ping function they could share with me. I have done some searching on this but cannot find anything specifically for vb2003. Sub PingComputer If PingStatus(PCName) = "Success" Then
3
1243
by: jacob navia | last post by:
Mr Randy Howard has his views about C. C programmers that develop GUI applications are Neaderntals and (of course) he agrees with Mr Heathfield: Heathfield: Howard:
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8247
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.