473,756 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9812
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.goo glegroups.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,siz eof(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.re mcomp.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.re mcomp.frwrote:

>>TK******@gmai l.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)(str uct __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;/*WSAGetLastErro r() 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(PingInterf ace *);

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

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.securityfoc us.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.re mcomp.frwrote:
Richard Bos a écrit :
jacob navia <ja***@jacob.re mcomp.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
2267
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 back in 0 milliseconds, others would come back in 15, but never in between. It would always jump...
2
21835
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 sure where to begin to keep the DOS window from closing. Dim stAppName As String Dim stIPAddress As String stAppName = "C:\WINDOWS\system32\ping.exe " stIPAddress =
0
7782
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 (192.168.1.* for instance) I have to do a FOR loop to itterate through all of the addresses. That it seems...
7
1802
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 if the web site is not running. Is there any easy method of doing the same. I do *not* want to use IP to ping and check the server. Thanks pradeep_tp
21
30531
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 linux ? Thanks in advance.
5
5587
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 control on it .
1
18508
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 What is the best way to ping a url in C# ?
4
1599
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 fail I figure the network is down. Any better ideas?
6
3459
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. Sub PingComputer If PingStatus(PCName) = "Success" Then
0
9456
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.