Ping!!!!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Ping!!!!

  1. #1
    Join Date
    Nov 2003
    Location
    Bangalore
    Posts
    78

    Ping!!!!

    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.

  2. #2
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    You can take the shortcut and use IcmpSendEcho(...)


    http://msdn.microsoft.com/library/de...mpsendecho.asp

  3. #3
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    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

  4. #4
    Join Date
    Nov 2003
    Location
    Bangalore
    Posts
    78

    Re:

    Originally posted by Mick
    You can take the shortcut and use IcmpSendEcho(...)


    http://msdn.microsoft.com/library/de...mpsendecho.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.

  5. #5
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    eh? how long of a delay? The only thing that could cause it is a DNS lookup.

  6. #6
    Join Date
    Nov 2003
    Location
    Bangalore
    Posts
    78

    Re:

    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.

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center