c - 如何在 C 中执行 IP 遍历

标签 c linux unix networking network-programming

我电脑的IP是192.168.1.101 over eth0。
我想知道 192.168.1.* 下的其他事件/使用 IP 是什么?
我期待在 192.168.1 下可 ping 通的 IP 地址列表。*
我怎么能在 C 中做到这一点?并且最好在 linux 平台上。
有可用的 C 函数吗?

最佳答案

C中没有内置发送ping包的函数。但是,有一个功能只是发送数据包。网上也有很多代码已经实现了ping。

您需要做的只是获取其中一个(例如 this)并循环 ping 网络中的所有地址。

但是,您应该知道,ping 并不是判断哪些地址正在使用的可靠方式。 RFC 792 - 互联网控制消息协议(protocol)说:

The Internet Protocol is not designed to be absolutely reliable. The purpose of these control messages is to provide feedback about problems in the communication environment, not to make IP reliable. There are still no guarantees that a datagram will be delivered or a control message will be returned. Some datagrams may still be undelivered without any report of their loss.

这意味着任何消息都可以很容易地丢失,没有通知。此外,目标不必响应。

关于c - 如何在 C 中执行 IP 遍历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4431798/

相关文章:

php - LAMP mcrypt 扩展

c - 调用 read 时超时的缺陷

c - 预处理器宏中的字符串处理

python - 意外标记 `(' python 脚本附近的语法错误

c++ - __FILE__ 编译时的宏操作处理

linux - 我在哪里可以找到 Amazon Linux 上的 “libgconf-2.so.4()(64bit)” 和 “xdg-utils” 依赖项?

linux - 符号链接(symbolic link)背后有什么?

c++ - 有什么适合学习Unix/Linux优势的好项目

c - 链表无限循环

在子进程中创建线程