Network Connectivity Programming.

This is a discussion on Network Connectivity Programming. within the C++ Programming forums, part of the General Programming Boards category; I need to create a program that will basically ping a remote host then do something every time that ping ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    18

    Lightbulb Network Connectivity Programming.

    I need to create a program that will basically ping a remote host then do something every time that ping fails to get a reply back. I've seen people post code like this before (see below), but this doesn't actually perform in any different fashion if the ping 'fails'.

    code:
    --------------------------------------------------------------------------------
    char blah1[10];
    int blah2[10];
    char command[20];

    blah1 = ping;
    blah2 = 127.0.0;

    strcat(command, blah1);
    strcat(command, blah2);

    system(command);
    --------------------------------------------------------------------------------
    Language: C++
    Compiler: Borland C++
    OS: Windows NT

  2. #2
    a
    Guest
    how would you know if the above ping fails in the first place? you gonna get that to output into a file and then check if it failled or are you planning to write your own ping function?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    39
    Here's an idea:

    Try doing a connect() directly to the IP address you are trying to ping. You would have the information you want in just one function call (well, actually two. you'd do a socket() just before it).

    But the point is, you would not need to do a system() and have its output in a file and then read from a file, parse it. And not to mention handling all the potential errors conditions associated with disk IO.

    Your code would be something like:

    Code:
    mySocket = socket( /*args */ );
    if ( sock_fd == INVALID_SOCKET )
    {
       // handle error.
    }
    
    err = connect( mySocket, /* rest of the args */ );
    if ( ret_code == SOCKET_ERROR )
    {
       // connect() failed. Equivalent to ping failed at system
    }
    Hope this helps.
    <Signature
    name="Ruchikar"
    quote="discussions are forgotten, only code remains"/>

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    18

    Lightbulb

    Thanks Ruchikar! Let me take a stab at using the connect() function and see if I can get it to do what I need. Thanks again!
    Language: C++
    Compiler: Borland C++
    OS: Windows NT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 05:33 PM
  3. Need help with easy Network setup
    By the dead tree in forum Tech Board
    Replies: 9
    Last Post: 04-08-2005, 07:44 PM
  4. network problems
    By lucy in forum Tech Board
    Replies: 6
    Last Post: 01-01-2003, 02:33 PM
  5. WinXP Network Connections pop-up
    By DavidP in forum Tech Board
    Replies: 1
    Last Post: 10-02-2002, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21