2

I'm trying to make a program that will list all of the IP addresses of devices on a network. One of the main components of this is being able to ping devices. This program must work on Linux, Windows and Mac, so I chose the Boost library.

I managed to find this example in the documentation: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/icmp/ping.cpp

I am fairly experienced at C++ when using OpenGL 3.1 and Shaders but when I run this program it pings over and over (454+) and understanding it is throwing me for a loop (No pun intended) , it seems to contain a substantial amount of shorthand, functions I've never seen etc.

Is there a simpler method to ping a machine with Boost:asio? or Is there a way I can get this method to run just 4 times and return the average response time?

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
CoderWalker
  • 299
  • 4
  • 14

1 Answers1

3

In the linked example you have to change the handle_receive function to include a counter. When it has been called four times you tell the io_server object to stop (for this you either has to make it global, or store a reference to it in the pinger class) and not call start_receive.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thanks for the response. Do you know what part in the program is requesting another response? I don't want to kill the service if and let the other machine keep responding. – CoderWalker Sep 20 '12 at 02:26
  • @CoderWalker The part sending the "ping"? In the linked example that's `start_send` and `handle_timeout`. – Some programmer dude Sep 20 '12 at 05:00