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_Keit h)
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"