问题描述
我需要使用 IcmpSendEcho2 API 命令异步使用ApcRoutine 回调例程.
I have a need to use the IcmpSendEcho2 API command asynchronously using theApcRoutine callback routine.
我的一个问题是 ApcRoutine 的签名是什么样的我需要定义回调例程吗?
A question I have is what would the signature look like for the ApcRoutinecallback routine I need to define?
当我调用 IcmpSendEcho2 时,第三个参数会是什么样子?
When I call IcmpSendEcho2 what would the third parameter look like?
我有大约 15 个代理请求要发送.我应该只用 IcmpSendEcho2 请求一次还是多次.
I have some 15 proxy request to be sent. should I request with IcmpSendEcho2 only once or multiple times.
如果我需要一次发送许多 IcmpSendEcho2 请求.怎么会回调 ApcRoutine 知道完成了哪个 IcmpSendEcho2 调用.我猜这个ApcContext 参数在哪里发挥作用?
If I will need to send many IcmpSendEcho2 requests at one time. How willthe callback ApcRoutine know which IcmpSendEcho2 call is done. I guess thisis where the ApcContext parameter comes into play?
我在 MSDN 或其他地方找不到任何示例代码来演示如何到异步使用 IcmpSendEcho2 命令.
I can't find any example code on MSDN or elsewhere that demonstrates howtouse the IcmpSendEcho2 command asynchronously.
推荐答案
int ReplyCame(PVOID param)
{
char* szAddr = (char*) param;
printf("Replay Came for %s......\n", szAddr);
return 0;
}
char* szAddr1 = "172.18.1.1";
char* szAddr2 = "172.18.1.4";
int _tmain(int argc, _TCHAR* argv[])
{
char *SendData = "Data Buffer";
LPVOID ReplyBuffer;
HANDLE IcmpHandle = IcmpCreateFile();
IPAddr addr1 = inet_addr(szAddr1);
IPAddr addr2 = inet_addr(szAddr2);
ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
IcmpSendEcho2(IcmpHandle, NULL, (FARPROC)ReplyCame, szAddr1, addr1,
SendData, sizeof(SendData), NULL, ReplyBuffer, 8*sizeof(ReplyBuffer) +
sizeof(ICMP_ECHO_REPLY), 1000);
IcmpSendEcho2(IcmpHandle, NULL, (FARPROC)ReplyCame, szAddr2, addr2,
SendData, sizeof(SendData), NULL, ReplyBuffer, 8*sizeof(ReplyBuffer) +
sizeof(ICMP_ECHO_REPLY), 1000);
SleepEx(5000, TRUE);
return 0;
}
注意,如果你想使用replyBuffer,你需要先用IcmpParseReplies解析它.
Do notice that if you want to use the replyBuffer you need to parse it before with IcmpParseReplies.
这篇关于如何使用回调示例vc实现icmpsendecho2异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!