473,585 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ping

how to ping ip address from c language ?

May 25 '07 #1
5 7395
Sonda <wf**********@h otmail.comwrite s:
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
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
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"
May 25 '07 #4
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2243
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...
9
15297
by: Mantorok | last post by:
Hi all I want to ping an ipaddress/host to check for a response. Is there any easy way in C#/.Net to do this? Thanks Kev
2
5578
by: Eric Wenger | last post by:
I'm pretty new to C# and I'm trying to do what I believe should be a simple thing. I want to modify a program that is using the System.Net.NetworkInformation.Ping class to have some custom behavior. For example I would like to do a "TCP-ping" where I try to connect to a TCP port on a remote machine. It seems obvious to me that I should try...
0
7756
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...
0
1477
by: scotty | last post by:
I need to do a ping scan of a subnet. I can Enum through the IPs and do this, but it takes over 5 minutes as I can only create 1 process at a time. Does anyone know how I can create multiple Ping Processes so as to send out 255 pings at once? (sort of a reverse ping flood). FYI: using the " -n 1" switch with Ping will cause it to only send...
21
30501
by: Neel | last post by:
I am trying to "ping" a remote host in my C++/Redhat Linux code to check whether that host is connected or not. if (0 == system("ping -w 2 192.168.0.2)) But, in both cases (connected/disconnected), system call returns 0. Can someone please show what I am doing wrong? How to check the actual result of the ping status using C++ on Redhat...
5
5574
by: Deepak | last post by:
I am programing a ping application which pings various centers . I used timer loop and it pings one by one. Now when i finish pinging one center it should wait for the ping_completed function to be executed and then continue pinging another certer. The ping_completed function is called on completion of ping by the os and i have no...
1
18460
by: Krish | last post by:
All, I have an offline application that works online for some data syncronization. For data syncronization I access a webservice. I want to show whether my application is online or not by checking whether the application is able to access the webservice. If the webservice is accessible, the application is online. otherwise it is offline ...
3
8360
by: imughal | last post by:
I got the perl script which does following task. This solution reads in a line from a text file that is passed in as input parameter 1 to a Perl script. This script will then ping the machine using TCP pings to the remote hosts echo port and will return up/down and the ping response time. A second optional attribute may be passed in that will...
6
3450
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. ...
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7950
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...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
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...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
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...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
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.