473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Running ping

Hello.
I have a problem. I need to make a client-server application using
sockets (easy).
After they communicate server store information about client (IP, and
some data).
Later on i need to check if the client is connected (ive got his IP
and need to ping him).
I dont need to write whole ping function - just need a return
value :).
Ive googled but didnt find anything :(. Could someone help - how can i
run ping program/function from c?
Maybe there are other methods to find out is client connected :).
Help plz!

Apr 13 '07 #1
8 9796
TK******@gmail.com wrote:
....snip...

Could someone help - how can i
run ping program/function from c?
doesn't a simple system(" ping ***.***.***.*** ");help?
of course replace the *s with the ip address!
Apr 13 '07 #2

<TK******@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Hello.
I have a problem. I need to make a client-server application using
sockets (easy).
After they communicate server store information about client (IP, and
some data).
Later on i need to check if the client is connected (ive got his IP
and need to ping him).
I dont need to write whole ping function - just need a return
value :).
Ive googled but didnt find anything :(. Could someone help - how can i
run ping program/function from c?
Maybe there are other methods to find out is client connected :).
Help plz!
(OT) Find the appropriate newsgroup for your question.
A ping (in the sense of the *nix utility ping or whacking the echo port)
and an established connection have little to do with
each other.
(/OT)
Apr 13 '07 #3
TK******@gmail.com a écrit :
Hello.
I have a problem. I need to make a client-server application using
sockets (easy).
After they communicate server store information about client (IP, and
some data).
Later on i need to check if the client is connected (ive got his IP
and need to ping him).
I dont need to write whole ping function - just need a return
value :).
Ive googled but didnt find anything :(. Could someone help - how can i
run ping program/function from c?
Maybe there are other methods to find out is client connected :).
Help plz!
If you are using the lcc-win32 compiler system you can do:
#include <ping.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
PingInterface p;
memset(&p,0,sizeof(p));
p.HostName = "www.google.com";
if (ping(&p)) {
printf(Host %s is up\n,argv[1]);
}
else
printf(Host %s is down\n,argv[1]);
}

Apr 14 '07 #4
Thank you very much!!!
You helped a lot :-).
Apr 16 '07 #5
jacob navia <ja***@jacob.remcomp.frwrote:
TK******@gmail.com a écrit :
I dont need to write whole ping function - just need a return
value :).
If you are using the lcc-win32 compiler system you can do:
#include <ping.h>
This is a joke, right? You don't _really_ have a header all for
ping-like functionality, which probably consists of a single function
even with you?

Richard
Apr 16 '07 #6
Richard Bos a écrit :
jacob navia <ja***@jacob.remcomp.frwrote:

>>TK******@gmail.com a écrit :
>>>I dont need to write whole ping function - just need a return
value :).

>>If you are using the lcc-win32 compiler system you can do:
#include <ping.h>


This is a joke, right? You don't _really_ have a header all for
ping-like functionality, which probably consists of a single function
even with you?

Richard
It is a matter of design. Yes, there is a header for just the
ping function. The reason is that the interface is quite complicated.

typedef struct __Ping {
/* -------------input section -------------------------------------*/
char *HostName;/* Host name/Ip address of destination. Required */
int TotalPackets;/*OPTIONAL: Nb of packets to send before exiting.
Default is 5 packets */
int DataSize;/*OPTIONAL: Data size in the sent packets. Default: 32*/
int SleepTime;/* OPTIONAL: Time (in ms) to wait after each packet.
Default is 1000 ms. */
int MaxTimeouts;/*OPTIONAL: Nb. of Timeouts allowed.
*/
int (*Callback)(struct __Ping *);/* OPTIONAL: Callback function at
each packet received and at each timeout. */
int ttl;/* OPTIONAL: Time to live. Default is 128 */
int verbose;/* Optional: Whether to print messages to stdout or not.*/
/* -------------output section -----------------------------------*/
int TotalReceived; // OUT: Total packets received
int TotalSent; // OUT: Total packets sent
int MaxTime; // OUT: Maximum time (ms)
int MinTime; // OUT: Minimum time (ms)
int TotalTime; // OUT: Total time used
int Timeouts; // OUT: Number of timeouts
int Errorcode;/*WSAGetLastError() report when an error occurs, or
a negative number, specific to the ping function. */
int ShortPackets; /* OUT: Packets that weren't sent completely due to
errors */
char ip[MAXIPNAME];/* OUT: IP of destination (Can be the same as
HostName) */
/* ---------------- Per packet specific data ----------------------*/
int Bytes; // OUT: Bytes received
int Seq; // OUT: Sequence number
int Time; // OUT: Time for this packet
} PingInterface;

int ping(PingInterface *);

---------------------------------------------------------------------------

The ping.h header is included in the "netutils.h" header file, where
you have other functions that are network related.

In this times of multi-megabyte header files having a specific header
file for a function may look old fashioned and maybe it is, but it
allows the user to avoid name conflicts, for instance.
Apr 17 '07 #7
jacob navia wrote:
>
.... snip ...
>
It is a matter of design. Yes, there is a header for just the
ping function. The reason is that the interface is quite complicated.
.... snip ...
>
The ping.h header is included in the "netutils.h" header file, where
you have other functions that are network related.

In this times of multi-megabyte header files having a specific header
file for a function may look old fashioned and maybe it is, but it
allows the user to avoid name conflicts, for instance.
There is no netutils.h header in the standard C system.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 17 '07 #8
jacob navia <ja***@jacob.remcomp.frwrote:
Richard Bos a écrit :
jacob navia <ja***@jacob.remcomp.frwrote:
>TK******@gmail.com a écrit :

I dont need to write whole ping function - just need a return
value :).
>If you are using the lcc-win32 compiler system you can do:
#include <ping.h>
This is a joke, right? You don't _really_ have a header all for
ping-like functionality, which probably consists of a single function
even with you?

It is a matter of design. Yes, there is a header for just the
ping function. The reason is that the interface is quite complicated.
IOW, you didn't trust yourself to get it right. Well, I can't blame you:
you can't seem to get topicality right, either.

Richard
Apr 17 '07 #9

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

Similar topics

3
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...
2
by: tripyre | last post by:
I recently resolved an issue I had with passing a variable to a call shell command, but now I need it to pause or leave the window open so I can manually close it. Below is my code, and I am not...
0
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:...
7
by: pradeep_TP | last post by:
hello all, I want to know how can I check whether a web site us running or not. I have used HttpWebRequest but when I give a web site address, It takes few number of seconds to throw exception...
21
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...
5
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...
1
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...
4
by: cj | last post by:
How would you suggest I test that my network drive is still up and running. Right now I'm going to write to a file at the root of the drive and then read it back in. If either the write or read...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.