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

Running ping

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a

<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

P: n/a
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

P: n/a
Thank you very much!!!
You helped a lot :-).
Apr 16 '07 #5

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.