By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

ping

P: n/a
how to ping ip address from c language ?

May 25 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Sonda <wf**********@hotmail.comwrites:
how to ping ip address from c language ?
I guess you do not like the idea of using system?
However that's the only way for doing that "portable".
However if you leave Ansi-C grounds you surely will find a acceptable
solution. See e.g
http://english.geekpage.jp/programmi.../send-icmp.php

Regards
Friedrich

--
Please remove just-for-news- to reply via e-mail.
May 25 '07 #2

P: n/a
Sonda wrote:
how to ping ip address from c language ?
http://www.faqs.org/rfcs/rfc792.html

The inventor of ping, Mike Muuss, wrote the first ping program in day.. and
put it into public domain:

http://www.ping127001.com/pingpage/ping.html

--
Tor <torust [at] online [dot] no>

May 25 '07 #3

P: n/a
Tor Rustad <to****@online.nowrites:
Sonda wrote:
>how to ping ip address from c language ?

http://www.faqs.org/rfcs/rfc792.html

The inventor of ping, Mike Muuss, wrote the first ping program in day.. and
put it into public domain:

http://www.ping127001.com/pingpage/ping.html
It's a pity that it's provided with a ".html" suffix. When I view the
page in my browser, the #include directives are messed up, and
probably other things as well.

The problem is that the <predirective doesn't actually say to
display plain text without interpreting it; things that look like HTML
directives are still processed.

You can download the raw file, remove everything up to and including
the "<pre>" directive, and try to compile it.

But note that the code is inherently non-portable (as it must be,
since standard C doesn't have the required facilities). Of the
headers it includes, only two are standard:

#include <stdio.h>
#include <errno.h>
#include <sys/time.h>

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>

#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netdb.h>

And it failed to compile on four different systems I just tried
(Cygwin, Solaris, Red Hat, AIX) -- all of which already have their own
"ping" programs, of course.

A solution to the original problem that's fairly likely to work on any
system where this is even possible is

system("ping ...");

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 25 '07 #4

P: n/a
Keith Thompson wrote:
Tor Rustad <to****@online.nowrites:
>The inventor of ping, Mike Muuss, wrote the first ping program in day..
and put it into public domain:

http://www.ping127001.com/pingpage/ping.html

It's a pity that it's provided with a ".html" suffix. When I view the
page in my browser, the #include directives are messed up, and
probably other things as well.
Yeah, I used "View Source" function in the browser, or you could get the raw
page via wget... or telnet.

And it failed to compile on four different systems I just tried
(Cygwin, Solaris, Red Hat, AIX) -- all of which already have their own
"ping" programs, of course.
Hehe.. you might have better luck with BSD installation from 1983! Still
it's an interesting read of a historical hack:

http://ftp.arl.mil:80/~mike/ping.html
--
Tor <torust [at] online [dot] no>

May 26 '07 #5

P: n/a
Tor Rustad wrote:
Sonda wrote:
>how to ping ip address from c language ?

http://www.faqs.org/rfcs/rfc792.html

The inventor of ping, Mike Muuss, wrote the first ping program in day.. and
put it into public domain:

http://www.ping127001.com/pingpage/ping.html
As an alternative, here's the source code link from Mike's webpage
http://ftp.arl.army.mil/pub/ping.shar

If you want the whole story about ping, Mike's page gives the scoop:
http://ftp.arl.mil/~mike/ping.html

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------

May 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.