Click to See Complete Forum and Search --> : Ping!!!!
ilamparithi
March 5th, 2004, 03:02 AM
Hi All,
I need to write a pgm to ping a system.
Also, i need to specify a timeout for that.
How to do that ?
Becoz most of the code to ping uses socket (even ICMP calls) commands like inet_addr.
Since these commands are used, when the system if not present takes a lot of time.
So how to write a pgm to ping a system by specifying Timeout?
With Regards,
A.Ilamparithi.
Mick
March 5th, 2004, 03:08 AM
You can take the shortcut and use IcmpSendEcho(...)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho.asp
Marc from D
March 5th, 2004, 03:24 AM
at least under win98 there is a DOS-commando ping that does almost everyhting you ask for. The only difficulty seems to analyze the results....
Maybe you just want to write a batch file?
just type "ping /?" in your DOS-box
Marc
ilamparithi
March 5th, 2004, 04:48 AM
Originally posted by Mick
You can take the shortcut and use IcmpSendEcho(...)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho.asp
Hi,
If you see at the above link, you can find an example like this
// Declare and initialize variables
char *SendData = "Data Buffer";
LPVOID ReplyBuffer;
ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
if ((dwRetVal = IcmpSendEcho(hIcmpFile,
inet_addr("123.456.789.0"),
SendData, sizeof(SendData),
NULL, ReplyBuffer,
sizeof(ReplyBuffer) + sizeof(ICMP_ECHO_REPLY),
1000)) != 0) {
printf("\tReceived %ld messages.\n", dwRetVal);
printf("\tMessage: %s\n", ReplyBuffer);
}
else {
printf("\tCall to IcmpSendEcho() failed.\n");
printf("\tError: %ld\n", GetLastError());
}
Even If you specify TIME OUT in IcmpSendEcho, if the system is down(offline) you can notice that it will take more time. This is becoz of inet_addr call used there. If the system is offline, this call takes lot of time and is the reason for delay.
With Best Regards,
A.Ilamparithi.
Mick
March 5th, 2004, 05:35 AM
eh? how long of a delay? The only thing that could cause it is a DNS lookup.
ilamparithi
March 5th, 2004, 07:18 AM
Originally posted by Mick
eh? how long of a delay? The only thing that could cause it is a DNS lookup.
Hi,
The delay is much larger. It is nearly 1.5 seconds.(in case of a offline system). But i want th timeout to be only 150 ms.
With Thanks,
A.Ilamparithi.
Andreas Masur
March 6th, 2004, 03:10 PM
[Moved thread]
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.