什么是最好的方法ping在c ++在linux下? [英] What is the best method to ping in c++ under linux?

查看:137
本文介绍了什么是最好的方法ping在c ++在linux下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从c ++代码调用ping。我想轻松读取输出以进一步使用。

I have to call ping from c++ code.I'd like to easily read the output for further utilizations.

我想出了两个解决方案:

I have come up with two solutions:


  • 使用分叉和管道,将ping输出重定向到管道,然后解析它

  • 库适合直接使用ping(ip_addresss)函数

我想要后者,但我没有找到任何东西这显然是一个标准的解决方案。

I'd like the latter but i didn't find anything that was clearly a standard solution.

你会怎么做?

推荐答案

我会选择第一个选项。 Linux是围绕着小型,专门的应用程序的概念,它做一件很好的事情,与管道沟通。你的应用程序不应该包括一个库来实现ping,因为已经有一个内置的命令来执行它,它工作得很好!

I would go with your first option. Linux is built around the concept of having small, specialized apps which do one thing really well, communicating with pipes. Your app shouldn't include a library to implement ping, since there is already a built-in command to do it, and it works very well!

这篇关于什么是最好的方法ping在c ++在linux下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆