IcmpSendEcho2 broken in Windows 2008 Server?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Testing some existing code with Windows 2008 Server. IcmpSendEcho2 seems to crash on Windows 2008 Server.<br/>I tried the code sample from the SDK and I saw the same issue (see code below). The exact sample from the SDK (using the synchronous call) works fine but as soon as I try to use an asynchronous call, it crashes. The same code works perfectly on WinXP. The code crashes right after the callback returns...<br/>This just does not make sense.<br/>Could anyone confirm that this is an existing bug or let me know what I am doing wrong.<br/><br/><br/>Test code:<br/><br/>#define PIO_APC_ROUTINE_DEFINED
#include <winsock2.h><br/>#include <iphlpapi.h><br/>#include <stdio.h><br/>#include <stdlib.h><br/>#include <winternl.h><br/>#include <icmpapi.h>
PIO_APC_ROUTINE GotIt(PVOID param, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved)<br/>{<br/>  printf("GOT IT!n");<br/>  return NULL;<br/>}
<br/>int __cdecl main(int argc, char **argv)<br/>{
    // Declare and initialize variables
    HANDLE hIcmpFile;<br/>    unsigned long ipaddr = INADDR_NONE;<br/>    DWORD dwRetVal = 0;<br/>    DWORD dwError = 0;<br/>    char SendData[] = "Data Buffer";<br/>    LPVOID ReplyBuffer = NULL;<br/>    DWORD ReplySize = 0;
    // Validate the parameters<br/>    if (argc != 2) {<br/>        printf("usage: %s IP addressn", argv[0]);<br/>        return 1;<br/>    }
    ipaddr = inet_addr(argv[1]);<br/>    if (ipaddr == INADDR_NONE) {<br/>        printf("usage: %s IP addressn", argv[0]);<br/>        return 1;<br/>    }
    hIcmpFile = IcmpCreateFile();<br/>    if (hIcmpFile == INVALID_HANDLE_VALUE) {<br/>        printf("tUnable to open handle.n");<br/>        printf("IcmpCreatefile returned error: %ldn", GetLastError());<br/>        return 1;<br/>    }<br/>    // Allocate space for at a single reply<br/>    ReplySize = sizeof (ICMP_ECHO_REPLY) + sizeof (SendData) + 8;<br/>    ReplyBuffer = (VOID *) malloc(ReplySize);<br/>    if (ReplyBuffer == NULL) {<br/>        printf("tUnable to allocate memory for reply buffern");<br/>        return 1;<br/>    }
    dwRetVal = IcmpSendEcho2(hIcmpFile, NULL, (PIO_APC_ROUTINE)GotIt, NULL,<br/>                             ipaddr, SendData, sizeof (SendData), NULL,<br/>                             ReplyBuffer, ReplySize, 1000);
    SleepEx(5000, TRUE);<br/>    return 0;<br/>}
I tried to use the latest SDK but still no luck.<br/><br/>Thanks.

View the full article
 
Back
Top