Running ping

T

TKowalcz

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!
 
M

Mark

(e-mail address removed) 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!
 
B

Barry

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)
 
J

jacob navia

(e-mail address removed) 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]);
}
 
R

Richard Bos

jacob navia said:
(e-mail address removed) a écrit :
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
 
J

jacob navia

Richard Bos a écrit :
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.
 
C

CBFalconer

jacob said:
.... 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
 
R

Richard Bos

jacob navia said:
Richard Bos a écrit :

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top