2014-10-20 313 views
1

我一直在尋找使用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,同樣的設備也失敗了。

+0

您的代碼看起來與函數的MSDN頁面上發佈的示例非常相似。您是否嘗試過運行網絡捕獲工具以查看數據包是否真的離開主機? – 2014-10-20 21:33:59

+0

11010是'IP_REQ_TIMED_OUT'。 – 2014-10-20 22:30:47

+0

是的,ping.exe始終小於2ms到我的本地局域網路由器......我會嘗試在Wireshark中比較它們。 – 2014-10-21 08:13:00

回答

0

嘗試使用管理員權限運行。

+0

這不提供問題的答案。一旦你有足夠的[聲譽](https://stackoverflow.com/help/whats-reputation),你將可以[對任何帖子發表評論](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [來自評論](/ review/low-quality-posts/17003454) – wasthishelpful 2017-08-11 10:19:49