How to ping using C sockets

后端 未结 2 586
别那么骄傲
别那么骄傲 2021-01-12 04:14
  • Compiler: Code::Blocks(GNU GCC)
  • Platform: Windows(x86)
  • Includes: winsock.h winsock2.h (ws2_32 is linked as well)

I am currently tryin

2条回答
  •  滥情空心
    2021-01-12 04:47

    It looks like you want a real solution, not just reimplementing PING for the sake of it.

    I recommend using IP helper (ICMP.dll on pre-WinXP systems), specifically, IcmpSendEcho (or its enhanced versions, IcmpSendEcho2, IcmpSendEcho2Ex, for asynchronous operations).

    There is a complete example of "pinging" a host on MSDN. It may be a good starting point.

    Update: for GCC (mingw), link with -liphlpapi.

提交回复
热议问题