我一直在尋找使用IcmpSendEcho
,並發現它將無法ping某些設備(例如我的BT家庭Hub 4)GetLastError
報告11010.雖然對於其他設備,它工作正常在同一個系統上執行)。相比之下,所有這些設備上的ping.exe
都成功了,但我不知道Ping
的實現方式有何不同。到目前爲止,我嘗試過的所有情況都是IPv4,我直接提供的(所以沒有DNS等)。IcmpSendEcho失敗,但「ping」成功
hIcmpFile = IcmpCreateFile();
ipAddress = inet_addr(ipAddressStr);
...hIcmpFile is reused
static const WORD sendSize = 32;
static const DWORD replySize = sizeof(ICMP_ECHO_REPLY) + sendSize;
char sendData[sendSize] = { 0 };
char replyBuffer[replySize];
auto ret = IcmpSendEcho(hIcmpFile, ipAddress, sendData, sendSize, NULL, replyBuffer, replySize, 1000);
if (ret == 0)
{
auto error = GetLastError();
我發現的唯一的其他報告是what would cause ICMPsendEcho to fail when ping.exe succeeds。但是這些答案似乎與我的問題不同。我嘗試過使用不同的有效負載大小,並且我嘗試了IcmpSendEcho2
,同樣的設備也失敗了。
您的代碼看起來與函數的MSDN頁面上發佈的示例非常相似。您是否嘗試過運行網絡捕獲工具以查看數據包是否真的離開主機? – 2014-10-20 21:33:59
11010是'IP_REQ_TIMED_OUT'。 – 2014-10-20 22:30:47
是的,ping.exe始終小於2ms到我的本地局域網路由器......我會嘗試在Wireshark中比較它們。 – 2014-10-21 08:13:00