I have to ping the given IP address and I need to print the below values in C++. It is fine to use popen and get the output.
1) Average Response Time 2) Data Block Size 3) Failure Count 4) Max. Response time 5) Min. Response time 6) Number Of Repetitions 7) Success Count 8) TimeOut
If I use popen, I will get a file pointer and I need to read on this file pointer to get the whole output and I have to extract the values using some string manipulation. Can any one please let me know if there is any other way instead of using string manipulation? Is there any data structure will be maintained by Operating System through which I can get the values after executing ping command?
Advertisement
Answer
I can’t think of a BETTER way than extracting the results from the string your read. Exactly the BEST way to parse the string, I’m not sure of [mostly because I haven’t spent much time thinking about that!]
An alternative is of course to write your own internal implementation of ping
, but I’m fairly sure that is a whole lot more work than using a parser on the popen
on the system ping
– unless you want VERY portable code [but that’d then also require a very portable networking package, since native networking is not very portable either].