本文介绍了C套接字Ping命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我一些关于如何使用C套接字设置ping方法的教程吗?使用beej的指南,我已经能够在两个设备之间建立连接,但现在我想在开始实际连接之前设置一个方法ping所有可用的设备。我从来没有这样做过,所以你会做一些事情,如设置一个多播套接字广播一个空的数据包,然后让该空包的接收者填充它的IP地址,并返回现在完整的数据包,这样你有地址开始连接?

Can someone point me to some tutorial on how to set up a ping method using C sockets? Using beej's guide, I've been able to set up a connection between two devices, but now I want to setup a method that pings for all available devices before starting an actual connection. I've never done this before, so would you do something like set up a multicast socket to broadcast an empty data packet and then have the receiver of that empty packet fill it with their IP address and return that now full data packet so that you have the address to start the connection? Any guide's/ help would be appreciated!

推荐答案

大多数当前IP协议栈不会响应对广播地址的ping请求。该功能被滥用于拒绝服务攻击。

Most current IP stacks will not respond to a ping request to a broadcast address. The feature was abused for denial of service attacks.

实现真正的ping实现并不容易,我建议您使用现有的lib:

Implementing a real ping implementation won't be easy, I'd suggest you use an existing lib:http://www.kernelthread.com/projects/hanoi/html/icmp.html

但是你必须手动遍历子网上的所有IP地址,让他们回应。

But you will have to manually iterate through all of the IP addrs on your subnet to get them to respond.

这篇关于C套接字Ping命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:59