using System; using System.Runtime.InteropServices; using static Vanara.PInvoke.Ws2_32; namespace Vanara.PInvoke { public static partial class IpHlpApi { /// The routine that is called when the calling thread is in an alertable thread and an ICMPv6 reply arrives. /// /// The ApcContext parameter passed to the Icmp6SendEcho2 function. This parameter can be used by the application to identify the /// Icmp6SendEcho2 request that the callback function is responding to. /// /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. /// /// This parameter is reserved. [PInvokeData("wdm.h", MSDNShortId = "1ce2b1d0-a8b2-4a05-8895-e13802690a7b")] public delegate void PIO_APC_ROUTINE(IntPtr ApcContext, ref IO_STATUS_BLOCK IoStatusBlock, uint Reserved); /// The Icmp6CreateFile function opens a handle on which IPv6 ICMP echo requests can be issued. /// /// The Icmp6CreateFile function returns an open handle on success. On failure, the function returns /// INVALID_HANDLE_VALUE. Call the GetLastError function for extended error information. /// /// /// /// The Icmp6CreateFile function opens a handle on which IPv6 ICMP echo requests can be issued. The Icmp6SendEcho2 function is /// used to send the IPv6 ICMP echo requests. The Icmp6ParseReplies function is used to parse the IPv6 ICMP replies. The /// IcmpCloseHandle function is used to close the ICMP handle opened by the Icmp6CreateFile function. /// /// For IPv4, use the IcmpCreateFile function. /// For IPv4, use the IcmpCreateFile, IcmpSendEcho, IcmpSendEcho2, IcmpSendEcho2Ex, and IcmpParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// The following example opens a handle on which IPv6 ICMP echo requests can be issued. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmp6createfile HANDLE Icmp6CreateFile( ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "2ddb23d8-a4e6-47c4-a552-2815ccaf055f")] public static extern SafeIcmpHandle Icmp6CreateFile(); /// /// The Icmp6ParseReplies function parses the reply buffer provided and returns an IPv6 ICMPv6 echo response reply if found. /// /// /// A pointer to the buffer passed to the Icmp6SendEcho2 function. This parameter is points to an ICMPV6_ECHO_REPLY structure to hold /// the response. /// /// The size, in bytes, of the buffer pointed to by the ReplyBuffer parameter. /// /// /// The Icmp6ParseReplies function returns 1 on success. In this case, the Status member in the ICMPV6_ECHO_REPLY /// structure pointed to by the ReplyBuffer parameter will be either IP_SUCCESS if the target node responded or IP_TTL_EXPIRED_TRANSIT. /// /// If the return value is zero, extended error information is available through GetLastError. /// /// /// Return code /// Description /// /// /// ERROR_GEN_FAILURE /// /// A general failure occurred. This error is returned if the ReplyBuffer parameter is a NULL pointer or the ReplySize parameter is zero. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The Icmp6ParseReplies function is used by IPv6 to parse replies that result from an ICMPv6 echo request. The /// Icmp6ParseReplies function parses a reply buffer previously passed to the Icmp6SendEcho2 function. Use the /// Icmp6ParseReplies function only with the Icmp6SendEcho2 function. /// /// /// The Icmp6ParseReplies function cannot be used on a reply buffer previously passed to IcmpSendEcho or IcmpSendEcho2 for IPv4. /// /// For IPv4, use the IcmpCreateFile, IcmpSendEcho, IcmpSendEcho2, IcmpSendEcho2Ex, and IcmpParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmp6parsereplies DWORD Icmp6ParseReplies( LPVOID // ReplyBuffer, DWORD ReplySize ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "b4d63ffd-37ad-4901-b017-205fb15381e7")] public static extern Win32Error Icmp6ParseReplies(IntPtr ReplyBuffer, uint ReplySize); /// /// The Icmp6SendEcho2 function sends an IPv6 ICMPv6 echo request and returns either immediately (if Event or ApcRoutine is /// non- NULL) or returns after the specified time-out. The ReplyBuffer contains the IPv6 ICMPv6 echo response, if any. /// /// The open handle returned by Icmp6CreateFile. /// /// /// An event to be signaled whenever an ICMPv6 response arrives. If this parameter is specified, it requires a handle to a valid /// event object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMPv6 reply arrives. On Windows Vista and /// later, PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather /// than FARPROC. /// /// /// On Windows Server 2003 and Windows XP, PIO_APC_ROUTINE_DEFINED must not be defined to force the datatype for this /// parameter to FARPROC. /// /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMPv6 response arrives or /// an error occurs. /// /// The IPv6 source address on which to issue the echo request, in the form of a sockaddr structure. /// The IPv6 destination address of the echo request, in the form of a sockaddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IPv6 header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, /// this parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// Note On Windows Server 2003 and Windows XP, the RequestOptions parameter is not optional and must not be NULL and only the /// Ttl and Flags members are used. /// /// /// /// A pointer to a buffer to hold replies to the request. Upon return, the buffer contains an ICMPV6_ECHO_REPLY structure followed by /// the message body from the ICMPv6 echo response reply data. The buffer must be large enough to hold at least one /// ICMPV6_ECHO_REPLY structure plus the number of bytes of data specified in the RequestSize parameter. This buffer should /// also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The size, in bytes, of the reply buffer pointed to by the ReplyBuffer parameter. This buffer should be large enough to hold at /// least one ICMPV6_ECHO_REPLY structure plus RequestSize bytes of data. This buffer should also be large enough to also hold 8 more /// bytes of data (the size of an ICMP error message) plus space for an IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. This parameter is only used if the Icmp6SendEcho2 function is called /// synchronously. So this parameter is not used if either the ApcRoutine or Eventparameter are not NULL. /// /// /// /// When called synchronously, the Icmp6SendEcho2 function returns the number of replies received and stored in ReplyBuffer. /// If the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the Icmp6SendEcho2 function returns ERROR_IO_PENDING to indicate the operation is in progress. /// The results can be retrieved later when the event specified in the Event parameter signals or the callback function in the /// ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// This function is not supported on this system. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The data area passed to a system call is too small. This error is returned if the ReplySize parameter indicates that the buffer /// pointed to by the ReplyBuffer parameter is too small. /// /// /// /// ERROR_INVALID_PARAMETER /// One of the parameters is invalid. This error is returned if the IcmpHandle parameter contains an invalid handle. /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to Icmp6SendEcho2 and is not an indication /// of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to process this command. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv6 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The Icmp6SendEcho2 function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The Icmp6SendEcho2 function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the Icmp6ParseReplies function. /// /// /// If the Event parameter is specified, the Icmp6SendEcho2 function is called asynchronously. The event specified in the /// Event parameter is signaled whenever an ICMPv6 response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the Icmp6SendEcho2 function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMPv6 response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMPv6 response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// On Windows Vista and later, any application that calls Icmp6SendEcho2 function asynchronously using the ApcRoutine /// parameter must define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE /// rather than FARPROC. /// /// /// On Windows Vista and later, the callback function pointed to by the ApcRoutine must be defined as a function of type VOID /// with the following syntax: /// /// On Windows Vista and later, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the Icmp6SendEcho2 function. This parameter can be used by the application to identify the /// Icmp6SendEcho2 request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// On Windows Server 2003 and Windows XP, any application that calls the Icmp6SendEcho2 function asynchronously using the /// ApcRoutine parameter must not define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to /// FARPROC rather than PIO_APC_ROUTINE. /// /// /// On Windows Server 2003 and Windows XP, the callback function pointed to by the ApcRoutine must be defined as a function of type /// VOID with the following syntax: /// /// On Windows Server 2003 and Windows XP, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the Icmp6SendEcho2 function. This parameter can be used by the application to identify the /// Icmp6SendEcho2 request that the callback function is responding to. /// /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the Icmp6SendEcho2 function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the Icmp6SendEcho2 function. /// /// For IPv4, use the IcmpCreateFile, IcmpSendEcho, IcmpSendEcho2, IcmpSendEcho2Ex, and IcmpParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmp6sendecho2 DWORD Icmp6SendEcho2( HANDLE IcmpHandle, // HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, sockaddr_in6 *SourceAddress, sockaddr_in6 *DestinationAddress, LPVOID // RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "622c769b-ede8-4bc2-ac54-98de47ae1fed")] public static extern Win32Error Icmp6SendEcho2(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, in SOCKADDR_IN6 SourceAddress, in SOCKADDR_IN6 DestinationAddress, [In] IntPtr RequestData, ushort RequestSize, in IP_OPTION_INFORMATION RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The Icmp6SendEcho2 function sends an IPv6 ICMPv6 echo request and returns either immediately (if Event or ApcRoutine is /// non- NULL) or returns after the specified time-out. The ReplyBuffer contains the IPv6 ICMPv6 echo response, if any. /// /// The open handle returned by Icmp6CreateFile. /// /// /// An event to be signaled whenever an ICMPv6 response arrives. If this parameter is specified, it requires a handle to a valid /// event object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMPv6 reply arrives. On Windows Vista and /// later, PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather /// than FARPROC. /// /// /// On Windows Server 2003 and Windows XP, PIO_APC_ROUTINE_DEFINED must not be defined to force the datatype for this /// parameter to FARPROC. /// /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMPv6 response arrives or /// an error occurs. /// /// The IPv6 source address on which to issue the echo request, in the form of a sockaddr structure. /// The IPv6 destination address of the echo request, in the form of a sockaddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IPv6 header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, /// this parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// Note On Windows Server 2003 and Windows XP, the RequestOptions parameter is not optional and must not be NULL and only the /// Ttl and Flags members are used. /// /// /// /// A pointer to a buffer to hold replies to the request. Upon return, the buffer contains an ICMPV6_ECHO_REPLY structure followed by /// the message body from the ICMPv6 echo response reply data. The buffer must be large enough to hold at least one /// ICMPV6_ECHO_REPLY structure plus the number of bytes of data specified in the RequestSize parameter. This buffer should /// also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The size, in bytes, of the reply buffer pointed to by the ReplyBuffer parameter. This buffer should be large enough to hold at /// least one ICMPV6_ECHO_REPLY structure plus RequestSize bytes of data. This buffer should also be large enough to also hold 8 more /// bytes of data (the size of an ICMP error message) plus space for an IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. This parameter is only used if the Icmp6SendEcho2 function is called /// synchronously. So this parameter is not used if either the ApcRoutine or Eventparameter are not NULL. /// /// /// /// When called synchronously, the Icmp6SendEcho2 function returns the number of replies received and stored in ReplyBuffer. /// If the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the Icmp6SendEcho2 function returns ERROR_IO_PENDING to indicate the operation is in progress. /// The results can be retrieved later when the event specified in the Event parameter signals or the callback function in the /// ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// This function is not supported on this system. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The data area passed to a system call is too small. This error is returned if the ReplySize parameter indicates that the buffer /// pointed to by the ReplyBuffer parameter is too small. /// /// /// /// ERROR_INVALID_PARAMETER /// One of the parameters is invalid. This error is returned if the IcmpHandle parameter contains an invalid handle. /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to Icmp6SendEcho2 and is not an indication /// of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to process this command. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv6 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The Icmp6SendEcho2 function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The Icmp6SendEcho2 function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the Icmp6ParseReplies function. /// /// /// If the Event parameter is specified, the Icmp6SendEcho2 function is called asynchronously. The event specified in the /// Event parameter is signaled whenever an ICMPv6 response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the Icmp6SendEcho2 function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMPv6 response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMPv6 response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// On Windows Vista and later, any application that calls Icmp6SendEcho2 function asynchronously using the ApcRoutine /// parameter must define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE /// rather than FARPROC. /// /// /// On Windows Vista and later, the callback function pointed to by the ApcRoutine must be defined as a function of type VOID /// with the following syntax: /// /// On Windows Vista and later, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the Icmp6SendEcho2 function. This parameter can be used by the application to identify the /// Icmp6SendEcho2 request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// On Windows Server 2003 and Windows XP, any application that calls the Icmp6SendEcho2 function asynchronously using the /// ApcRoutine parameter must not define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to /// FARPROC rather than PIO_APC_ROUTINE. /// /// /// On Windows Server 2003 and Windows XP, the callback function pointed to by the ApcRoutine must be defined as a function of type /// VOID with the following syntax: /// /// On Windows Server 2003 and Windows XP, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the Icmp6SendEcho2 function. This parameter can be used by the application to identify the /// Icmp6SendEcho2 request that the callback function is responding to. /// /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the Icmp6SendEcho2 function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the Icmp6SendEcho2 function. /// /// For IPv4, use the IcmpCreateFile, IcmpSendEcho, IcmpSendEcho2, IcmpSendEcho2Ex, and IcmpParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmp6sendecho2 DWORD Icmp6SendEcho2( HANDLE IcmpHandle, // HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, sockaddr_in6 *SourceAddress, sockaddr_in6 *DestinationAddress, LPVOID // RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "622c769b-ede8-4bc2-ac54-98de47ae1fed")] public static extern Win32Error Icmp6SendEcho2(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, in SOCKADDR_IN6 SourceAddress, in SOCKADDR_IN6 DestinationAddress, [In] IntPtr RequestData, ushort RequestSize, [Optional] IntPtr RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// The IcmpCloseHandle function closes a handle opened by a call to the IcmpCreateFile or Icmp6CreateFile functions. /// The handle to close. This handle must have been returned by a call to IcmpCreateFile or Icmp6CreateFile. /// /// If the handle is closed successfully the return value is TRUE, otherwise FALSE. Call the GetLastError function for /// extended error information. /// /// /// /// The IcmpCloseHandle function is exported from the Icmp.dll on Windows 2000. The IcmpCloseHandle function is /// exported from the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. /// Applications requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows /// versions should not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for /// the presence of IcmpCloseHandle in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the /// application should check for the presence of IcmpCloseHandle in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// The following example opens and closes a handle on which ICMP echo requests can be issued. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpclosehandle IPHLPAPI_DLL_LINKAGE BOOL IcmpCloseHandle( // HANDLE IcmpHandle ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "ce8f11bb-1e33-41bd-adb9-c18efadd4d0b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IcmpCloseHandle(IntPtr IcmpHandle); /// The IcmpCreateFile function opens a handle on which IPv4 ICMP echo requests can be issued. /// /// The IcmpCreateFile function returns an open handle on success. On failure, the function returns /// INVALID_HANDLE_VALUE. Call the GetLastError function for extended error information. /// /// /// /// The IcmpCreateFile function is exported from the Icmp.dll on Windows 2000. The IcmpCreateFile function is exported /// from the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. Applications /// requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should /// not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for the presence of /// IcmpCreateFile in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should /// check for the presence of IcmpCreateFile in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// The following example opens a handle on which ICMP echo requests can be issued. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpcreatefile IPHLPAPI_DLL_LINKAGE HANDLE IcmpCreateFile( ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "b435b38b-df86-4991-9772-c712c9ea606f")] public static extern SafeIcmpHandle IcmpCreateFile(); /// /// The IcmpParseReplies function parses the reply buffer provided and returns the number of ICMP echo request responses found. /// /// /// The buffer passed to IcmpSendEcho2. This is rewritten to hold an array of ICMP_ECHO_REPLY structures, its type is PICMP_ECHO_REPLY. /// On a 64-bit plaform, this buffer is rewritten to hold an array of ICMP_ECHO_REPLY32 structures, its type is PICMP_ECHO_REPLY32. /// /// The size, in bytes, of the buffer pointed to by the ReplyBuffer parameter. /// /// The IcmpParseReplies function returns the number of ICMP responses found on success. The function returns zero on error. /// Call GetLastError for additional error information. /// /// /// /// The IcmpParseReplies function should not be used on a reply buffer previously passed to IcmpSendEcho. The /// IcmpSendEcho function parses that buffer before returning to the user. Use this function only with IcmpSendEcho2. /// /// /// The IcmpParseReplies function is exported from the Icmp.dll on Windows 2000. The IcmpParseReplies function is /// exported from the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. /// Applications requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows /// versions should not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for /// the presence of IcmpParseReplies in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the /// application should check for the presence of IcmpParseReplies in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpparsereplies IPHLPAPI_DLL_LINKAGE DWORD // IcmpParseReplies( LPVOID ReplyBuffer, DWORD ReplySize ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "ec7c2a5f-5406-4350-b795-6e72fe25f62d")] public static extern uint IcmpParseReplies(IntPtr ReplyBuffer, uint ReplySize); /// /// The IcmpSendEcho function sends an IPv4 ICMP echo request and returns any echo response replies. The call returns when the /// time-out has expired or the reply buffer is filled. /// /// The open handle returned by the IcmpCreateFile function. /// The IPv4 destination address of the echo request, in the form of an IPAddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// A buffer to hold any replies to the echo request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by the options and data for the replies. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message). /// /// The time, in milliseconds, to wait for replies. /// /// /// The IcmpSendEcho function returns the number of ICMP_ECHO_REPLY structures stored in the ReplyBuffer. The status of each /// reply is contained in the structure. If the return value is zero, call GetLastError for additional error information. /// /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The data area passed to a system call is too small. This error is returned if the ReplySize parameter indicates that the buffer /// pointed to by the ReplyBuffer parameter is too small. /// /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The IcmpSendEcho function send an ICMP echo request to the specified address and returns the number of replies received /// and stored in ReplyBuffer. The IcmpSendEcho function is a synchronous function and returns after waiting for the time /// specified in the Timeout parameter for a response. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2 and IcmpSendEcho2Ex functions are enhanced version of IcmpSendEcho that support asynchronous operation. /// The IcmpSendEcho2Ex function also allows the source IP address to be specified. This feature is useful on computers with /// multiple network interfaces. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// /// The IcmpSendEcho function is exported from the Icmp.dll on Windows 2000. The IcmpSendEcho function is exported from /// the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. Applications /// requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should /// not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for the presence of /// IcmpSendEcho in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should check /// for the presence of IcmpSendEcho in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// /// The following example sends an ICMP echo request to the IP address specified on the command line and prints the information /// received from the first response. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho IPHLPAPI_DLL_LINKAGE DWORD IcmpSendEcho( // HANDLE IcmpHandle, IPAddr DestinationAddress, LPVOID RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID // ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "c3cdc535-2c13-48c6-9ab1-88cc5e5119b5")] public static extern uint IcmpSendEcho(SafeIcmpHandle IcmpHandle, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, in IP_OPTION_INFORMATION RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The IcmpSendEcho function sends an IPv4 ICMP echo request and returns any echo response replies. The call returns when the /// time-out has expired or the reply buffer is filled. /// /// The open handle returned by the IcmpCreateFile function. /// The IPv4 destination address of the echo request, in the form of an IPAddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// A buffer to hold any replies to the echo request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by the options and data for the replies. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message). /// /// The time, in milliseconds, to wait for replies. /// /// /// The IcmpSendEcho function returns the number of ICMP_ECHO_REPLY structures stored in the ReplyBuffer. The status of each /// reply is contained in the structure. If the return value is zero, call GetLastError for additional error information. /// /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The data area passed to a system call is too small. This error is returned if the ReplySize parameter indicates that the buffer /// pointed to by the ReplyBuffer parameter is too small. /// /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The IcmpSendEcho function send an ICMP echo request to the specified address and returns the number of replies received /// and stored in ReplyBuffer. The IcmpSendEcho function is a synchronous function and returns after waiting for the time /// specified in the Timeout parameter for a response. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2 and IcmpSendEcho2Ex functions are enhanced version of IcmpSendEcho that support asynchronous operation. /// The IcmpSendEcho2Ex function also allows the source IP address to be specified. This feature is useful on computers with /// multiple network interfaces. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// /// The IcmpSendEcho function is exported from the Icmp.dll on Windows 2000. The IcmpSendEcho function is exported from /// the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. Applications /// requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should /// not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for the presence of /// IcmpSendEcho in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should check /// for the presence of IcmpSendEcho in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// /// The following example sends an ICMP echo request to the IP address specified on the command line and prints the information /// received from the first response. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho IPHLPAPI_DLL_LINKAGE DWORD IcmpSendEcho( // HANDLE IcmpHandle, IPAddr DestinationAddress, LPVOID RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID // ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "c3cdc535-2c13-48c6-9ab1-88cc5e5119b5")] public static extern uint IcmpSendEcho(SafeIcmpHandle IcmpHandle, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, [Optional] IntPtr RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The IcmpSendEcho2 function sends an IPv4 ICMP echo request and returns either immediately (if Event or ApcRoutine is non- /// NULL) or returns after the specified time-out. The ReplyBuffer contains the ICMP echo responses, if any. /// /// The open handle returned by the ICMPCreateFile function. /// /// /// An event to be signaled whenever an ICMP response arrives. If this parameter is specified, it requires a handle to a valid event /// object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMPv4 reply arrives. On Windows Vista and /// later, PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather /// than FARPROC. /// /// /// On Windows Server 2003, Windows XP, and Windows 2000, PIO_APC_ROUTINE_DEFINED must not be defined to force the datatype /// for this parameter to FARPROC. /// /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMP response arrives or /// an error occurs. /// /// The IPv4 destination of the echo request, in the form of an IPAddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// /// A pointer to a buffer to hold any replies to the request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by options and data. The buffer must be large enough to hold at least one ICMP_ECHO_REPLY structure plus /// RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. /// /// /// When called synchronously, the IcmpSendEcho2 function returns the number of replies received and stored in ReplyBuffer. If /// the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the IcmpSendEcho2 function returns ERROR_IO_PENDING to indicate the operation is in progress. /// The results can be retrieved later when the event specified in the Event parameter signals or the callback function in the /// ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to IcmpSendEcho2 and is not an indication /// of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The IcmpSendEcho2 function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2 function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the IcmpParseReplies function. /// /// /// If the Event parameter is specified, the IcmpSendEcho2 function is called asynchronously. The event specified in the Event /// parameter is signaled whenever an ICMP response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the IcmpSendEcho2 function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMP response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMP response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// On Windows Vista and later, any application that calls IcmpSendEcho2 function asynchronously using the ApcRoutine /// parameter must define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE /// rather than FARPROC. /// /// /// On Windows Vista and later, the callback function pointed to by the ApcRoutine must be defined as a function of type VOID /// with the following syntax: /// /// On Windows Vista and later, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2 function. This parameter can be used by the application to identify the /// IcmpSendEcho2 request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// On Windows Server 2003, Windows XP, and Windows 2000, any application that calls the IcmpSendEcho2 function asynchronously /// using the ApcRoutine parameter must not define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter /// to FARPROC rather than PIO_APC_ROUTINE. /// /// /// On Windows Server 2003 and Windows XP, the callback function pointed to by the ApcRoutine must be defined as a function of type /// VOID with the following syntax: /// /// On Windows Server 2003, Windows XP, and Windows 2000, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2 function. This parameter can be used by the application to identify the /// IcmpSendEcho2 request that the callback function is responding to. /// /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the IcmpSendEcho2 function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the IcmpSendEcho2 function. /// /// /// The IcmpSendEcho2 function is exported from the Icmp.dll on Windows 2000. The IcmpSendEcho2 function is exported /// from the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. Applications /// requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should /// not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for the presence of /// IcmpSendEcho2 in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should check /// for the presence of IcmpSendEcho2 in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// /// The following example calls the IcmpSendEcho2 function synchronously. The example sends an ICMP echo request to the IP /// address specified on the command line and prints the information received from the first response. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho2 IPHLPAPI_DLL_LINKAGE DWORD IcmpSendEcho2( // HANDLE IcmpHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, IPAddr DestinationAddress, LPVOID RequestData, WORD // RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "1f70b6cc-9085-4eb8-b2cc-3b3d98d0ea46")] public static extern uint IcmpSendEcho2(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, in IP_OPTION_INFORMATION RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The IcmpSendEcho2 function sends an IPv4 ICMP echo request and returns either immediately (if Event or ApcRoutine is non- /// NULL) or returns after the specified time-out. The ReplyBuffer contains the ICMP echo responses, if any. /// /// The open handle returned by the ICMPCreateFile function. /// /// /// An event to be signaled whenever an ICMP response arrives. If this parameter is specified, it requires a handle to a valid event /// object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMPv4 reply arrives. On Windows Vista and /// later, PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather /// than FARPROC. /// /// /// On Windows Server 2003, Windows XP, and Windows 2000, PIO_APC_ROUTINE_DEFINED must not be defined to force the datatype /// for this parameter to FARPROC. /// /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMP response arrives or /// an error occurs. /// /// The IPv4 destination of the echo request, in the form of an IPAddr structure. /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// /// A pointer to a buffer to hold any replies to the request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by options and data. The buffer must be large enough to hold at least one ICMP_ECHO_REPLY structure plus /// RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. /// /// /// When called synchronously, the IcmpSendEcho2 function returns the number of replies received and stored in ReplyBuffer. If /// the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the IcmpSendEcho2 function returns ERROR_IO_PENDING to indicate the operation is in progress. /// The results can be retrieved later when the event specified in the Event parameter signals or the callback function in the /// ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to IcmpSendEcho2 and is not an indication /// of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// /// The IcmpSendEcho2 function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2 function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the IcmpParseReplies function. /// /// /// If the Event parameter is specified, the IcmpSendEcho2 function is called asynchronously. The event specified in the Event /// parameter is signaled whenever an ICMP response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the IcmpSendEcho2 function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMP response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMP response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// On Windows Vista and later, any application that calls IcmpSendEcho2 function asynchronously using the ApcRoutine /// parameter must define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE /// rather than FARPROC. /// /// /// On Windows Vista and later, the callback function pointed to by the ApcRoutine must be defined as a function of type VOID /// with the following syntax: /// /// On Windows Vista and later, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2 function. This parameter can be used by the application to identify the /// IcmpSendEcho2 request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// On Windows Server 2003, Windows XP, and Windows 2000, any application that calls the IcmpSendEcho2 function asynchronously /// using the ApcRoutine parameter must not define PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter /// to FARPROC rather than PIO_APC_ROUTINE. /// /// /// On Windows Server 2003 and Windows XP, the callback function pointed to by the ApcRoutine must be defined as a function of type /// VOID with the following syntax: /// /// On Windows Server 2003, Windows XP, and Windows 2000, the parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2 function. This parameter can be used by the application to identify the /// IcmpSendEcho2 request that the callback function is responding to. /// /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the IcmpSendEcho2 function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the IcmpSendEcho2 function. /// /// /// The IcmpSendEcho2 function is exported from the Icmp.dll on Windows 2000. The IcmpSendEcho2 function is exported /// from the Iphlpapi.dll on Windows XP and later. Windows version checking is not recommended to use this function. Applications /// requiring portability with this function across Windows 2000, Windows XP, Windows Server 2003 and later Windows versions should /// not statically link to either the Icmp.lib or the Iphlpapi.lib file. Instead, the application should check for the presence of /// IcmpSendEcho2 in the Iphlpapi.dll with calls to LoadLibrary and GetProcAddress. Failing that, the application should check /// for the presence of IcmpSendEcho2 in the Icmp.dll with calls to LoadLibrary and GetProcAddress. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// Examples /// /// The following example calls the IcmpSendEcho2 function synchronously. The example sends an ICMP echo request to the IP /// address specified on the command line and prints the information received from the first response. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho2 IPHLPAPI_DLL_LINKAGE DWORD IcmpSendEcho2( // HANDLE IcmpHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, IPAddr DestinationAddress, LPVOID RequestData, WORD // RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "1f70b6cc-9085-4eb8-b2cc-3b3d98d0ea46")] public static extern uint IcmpSendEcho2(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, [Optional] IntPtr RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The IcmpSendEcho2Ex function sends an IPv4 ICMP echo request and returns either immediately (if Event or ApcRoutine is /// non- NULL) or returns after the specified time-out. The ReplyBuffer contains the ICMP responses, if any. /// /// An open handle returned by the ICMPCreateFile function. /// /// /// An event to be signaled whenever an ICMP response arrives. If this parameter is specified, it requires a handle to a valid event /// object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMP reply arrives. /// PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather than FARPROC. /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMP response arrives or /// an error occurs. /// /// /// The IPv4 source address on which to issue the echo request. This address is in the form of an IPAddr structure. /// /// /// The IPv4 destination address for the echo request. This address is in the form of an IPAddr structure. /// /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// /// A pointer to a buffer to hold any replies to the request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by options and data. The buffer must be large enough to hold at least one ICMP_ECHO_REPLY structure plus /// RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. /// /// /// When called synchronously, the IcmpSendEcho2Ex function returns the number of replies received and stored in ReplyBuffer. /// If the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the IcmpSendEcho2Ex function returns ERROR_IO_PENDING to indicate the operation is in /// progress. The results can be retrieved later when the event specified in the Event parameter signals or the callback function in /// the ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to IcmpSendEcho2Ex and is not an /// indication of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The IcmpSendEcho2Ex function is available on Windows Server 2008 and later. /// /// The IcmpSendEcho2Ex function is an enhanced version of the IcmpSendEcho2 function that allows the user to specify the IPv4 /// source address on which to issue the ICMP request. The IcmpSendEcho2Ex function is useful in cases where a computer has /// multiple network interfaces. /// /// /// The IcmpSendEcho2Ex function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2Ex function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the IcmpParseReplies function. /// /// /// If the Event parameter is specified, the IcmpSendEcho2Ex function is called asynchronously. The event specified in the /// Event parameter is signaled whenever an ICMP response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the IcmpSendEcho2Ex function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMP response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMP response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// Any application that calls the IcmpSendEcho2Ex function asynchronously using the ApcRoutine parameter must define /// PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE rather than FARPROC. /// /// /// The callback function pointed to by the ApcRoutine must be defined as a function of type VOID with the following syntax: /// /// The parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2Ex function. This parameter can be used by the application to identify the /// IcmpSendEcho2Ex request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the IcmpSendEcho2Ex function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the IcmpSendEcho2Ex function. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho2ex IPHLPAPI_DLL_LINKAGE DWORD // IcmpSendEcho2Ex( HANDLE IcmpHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, IPAddr SourceAddress, IPAddr // DestinationAddress, LPVOID RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD // ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "7b2b2cae-650f-4ecb-aa2e-a55ee4026999")] public static extern uint IcmpSendEcho2Ex(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, IN_ADDR SourceAddress, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, in IP_OPTION_INFORMATION RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// The IcmpSendEcho2Ex function sends an IPv4 ICMP echo request and returns either immediately (if Event or ApcRoutine is /// non- NULL) or returns after the specified time-out. The ReplyBuffer contains the ICMP responses, if any. /// /// An open handle returned by the ICMPCreateFile function. /// /// /// An event to be signaled whenever an ICMP response arrives. If this parameter is specified, it requires a handle to a valid event /// object. Use the CreateEvent or CreateEventEx function to create this event object. /// /// For more information on using events, see Event Objects. /// /// /// The routine that is called when the calling thread is in an alertable thread and an ICMP reply arrives. /// PIO_APC_ROUTINE_DEFINED must be defined to force the datatype for this parameter to PIO_APC_ROUTINE rather than FARPROC. /// /// /// An optional parameter passed to the callback routine specified in the ApcRoutine parameter whenever an ICMP response arrives or /// an error occurs. /// /// /// The IPv4 source address on which to issue the echo request. This address is in the form of an IPAddr structure. /// /// /// The IPv4 destination address for the echo request. This address is in the form of an IPAddr structure. /// /// A pointer to a buffer that contains data to send in the request. /// The size, in bytes, of the request data buffer pointed to by the RequestData parameter. /// /// /// A pointer to the IP header options for the request, in the form of an IP_OPTION_INFORMATION structure. On a 64-bit platform, this /// parameter is in the form for an IP_OPTION_INFORMATION32 structure. /// /// This parameter may be NULL if no IP header options need to be specified. /// /// /// /// A pointer to a buffer to hold any replies to the request. Upon return, the buffer contains an array of ICMP_ECHO_REPLY structures /// followed by options and data. The buffer must be large enough to hold at least one ICMP_ECHO_REPLY structure plus /// RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// /// /// The allocated size, in bytes, of the reply buffer. The buffer should be large enough to hold at least one ICMP_ECHO_REPLY /// structure plus RequestSize bytes of data. /// /// /// This buffer should also be large enough to also hold 8 more bytes of data (the size of an ICMP error message) plus space for an /// IO_STATUS_BLOCK structure. /// /// /// The time, in milliseconds, to wait for replies. /// /// /// When called synchronously, the IcmpSendEcho2Ex function returns the number of replies received and stored in ReplyBuffer. /// If the return value is zero, call GetLastError for extended error information. /// /// /// When called asynchronously, the IcmpSendEcho2Ex function returns ERROR_IO_PENDING to indicate the operation is in /// progress. The results can be retrieved later when the event specified in the Event parameter signals or the callback function in /// the ApcRoutine parameter is called. /// /// If the return value is zero, call GetLastError for extended error information. /// If the function fails, the extended error code returned by GetLastError can be one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the IcmpHandle parameter contains an invalid handle. /// This error can also be returned if the ReplySize parameter specifies a value less than the size of an ICMP_ECHO_REPLY structure. /// /// /// /// ERROR_IO_PENDING /// /// The operation is in progress. This value is returned by a successful asynchronous call to IcmpSendEcho2Ex and is not an /// indication of an error. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Not enough memory is available to complete the operation. /// /// /// ERROR_NOT_SUPPORTED /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. /// /// /// IP_BUF_TOO_SMALL /// The size of the ReplyBuffer specified in the ReplySize parameter was too small. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The IcmpSendEcho2Ex function is available on Windows Server 2008 and later. /// /// The IcmpSendEcho2Ex function is an enhanced version of the IcmpSendEcho2 function that allows the user to specify the IPv4 /// source address on which to issue the ICMP request. The IcmpSendEcho2Ex function is useful in cases where a computer has /// multiple network interfaces. /// /// /// The IcmpSendEcho2Ex function is called synchronously if the ApcRoutine or Event parameters are NULL. When called /// synchronously, the return value contains the number of replies received and stored in ReplyBuffer after waiting for the time /// specified in the Timeout parameter. If the return value is zero, call GetLastError for extended error information. /// /// /// The IcmpSendEcho2Ex function is called asynchronously when either the ApcRoutine or Event parameters are specified. When /// called asynchronously, the ReplyBuffer and ReplySize parameters are required to accept the response. ICMP response data is copied /// to the ReplyBuffer provided and the application is signaled (when the Event parameter is specified) or the callback function is /// called (when the ApcRoutine parameter is specified). The application must parse the data pointed to by ReplyBuffer parameter /// using the IcmpParseReplies function. /// /// /// If the Event parameter is specified, the IcmpSendEcho2Ex function is called asynchronously. The event specified in the /// Event parameter is signaled whenever an ICMP response arrives. Use the CreateEvent function to create this event object. /// /// /// If the ApcRoutine parameter is specified, the IcmpSendEcho2Ex function is called asynchronously. The ApcRoutine parameter /// should point to a user-defined callback function. The callback function specified in the ApcRoutine parameter is called whenever /// an ICMP response arrives. The invocation of the callback function specified in the ApcRoutine parameter is serialized. /// /// /// If both the Event and ApcRoutine parameters are specified, the event specified in the Event parameter is signaled whenever an /// ICMP response arrives, but the callback function specified in the ApcRoutine parameter is ignored . /// /// /// Any application that calls the IcmpSendEcho2Ex function asynchronously using the ApcRoutine parameter must define /// PIO_APC_ROUTINE_DEFINED to force the datatype for the ApcRoutine parameter to PIO_APC_ROUTINE rather than FARPROC. /// /// /// The callback function pointed to by the ApcRoutine must be defined as a function of type VOID with the following syntax: /// /// The parameters passed to the callback function include the following: /// /// /// Parameter /// Description /// /// /// IN PVOID ApcContext /// /// The ApcContext parameter passed to the IcmpSendEcho2Ex function. This parameter can be used by the application to identify the /// IcmpSendEcho2Ex request that the callback function is responding to. /// /// /// /// IN PIO_STATUS_BLOCK IoStatusBlock /// /// A pointer to a IO_STATUS_BLOCK. This variable contains the final completion status and information about the operation. The /// number of bytes actually received in the reply is returned in the Information member of the IO_STATUS_BLOCK struct. The /// IO_STATUS_BLOCK structure is defined in the Wdm.h header file. /// /// /// /// IN ULONG Reserved /// This parameter is reserved. /// /// /// /// The callback function specified in the ApcRoutine parameter must be implemented in the same process as the application calling /// the IcmpSendEcho2Ex function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the IcmpSendEcho2Ex function. /// /// For IPv6, use the Icmp6CreateFile, Icmp6SendEcho2, and Icmp6ParseReplies functions. /// Note that the include directive for Iphlpapi.h header file must be placed before the Icmpapi.h header file. /// // https://docs.microsoft.com/en-us/windows/desktop/api/icmpapi/nf-icmpapi-icmpsendecho2ex IPHLPAPI_DLL_LINKAGE DWORD // IcmpSendEcho2Ex( HANDLE IcmpHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, IPAddr SourceAddress, IPAddr // DestinationAddress, LPVOID RequestData, WORD RequestSize, PIP_OPTION_INFORMATION RequestOptions, LPVOID ReplyBuffer, DWORD // ReplySize, DWORD Timeout ); [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] [PInvokeData("icmpapi.h", MSDNShortId = "7b2b2cae-650f-4ecb-aa2e-a55ee4026999")] public static extern uint IcmpSendEcho2Ex(SafeIcmpHandle IcmpHandle, [Optional] HANDLE Event, [Optional] PIO_APC_ROUTINE ApcRoutine, [Optional] IntPtr ApcContext, IN_ADDR SourceAddress, IN_ADDR DestinationAddress, IntPtr RequestData, ushort RequestSize, [Optional] IntPtr RequestOptions, IntPtr ReplyBuffer, uint ReplySize, uint Timeout); /// /// A driver sets an IRP's I/O status block to indicate the final status of an I/O request, before calling IoCompleteRequest for the IRP. /// /// /// /// Unless a driver's dispatch routine completes an IRP with an error status value, the lowest-level driver in the chain frequently /// sets the IRP's I/O status block to the values that will be returned to the original requester of the I/O operation. /// /// /// The IoCompletion routines of higher-level drivers usually check the I/O status block in IRPs completed by lower drivers. By /// design, the I/O status block in an IRP is the only information passed back from the underlying device driver to all higher-level /// drivers' IoCompletion routines. /// /// /// The operating system implements support routines that write IO_STATUS_BLOCK values to caller-supplied output buffers. For /// example, see ZwOpenFile or NtOpenFile. These routines return status codes that might not match the status codes in the /// IO_STATUS_BLOCK structures. If one of these routines returns STATUS_PENDING, the caller should wait for the I/O operation /// to complete, and then check the status code in the IO_STATUS_BLOCK structure to determine the final status of the /// operation. If the routine returns a status code other than STATUS_PENDING, the caller should rely on this status code instead of /// the status code in the IO_STATUS_BLOCK structure. /// /// For more information, see I/O Status Blocks. /// // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/ns-wdm-_io_status_block typedef struct _IO_STATUS_BLOCK // { union { NTSTATUS Status; PVOID Pointer; } DUMMYUNIONNAME; ULONG_PTR Information; } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; [PInvokeData("wdm.h", MSDNShortId = "1ce2b1d0-a8b2-4a05-8895-e13802690a7b")] [StructLayout(LayoutKind.Sequential)] public struct IO_STATUS_BLOCK { /// /// This is the completion status, either STATUS_SUCCESS if the requested operation was completed successfully or an /// informational, warning, or error STATUS_XXX value. For more information, see Using NTSTATUS values. /// [MarshalAs(UnmanagedType.SysUInt)] public NTStatus Status; /// /// This is set to a request-dependent value. For example, on successful completion of a transfer request, this is set to the /// number of bytes transferred. If a transfer request is completed with another STATUS_XXX, this member is set to zero. /// public IntPtr Information; } /// Provides a for an IMCP handle that is disposed using . public class SafeIcmpHandle : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeIcmpHandle(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeIcmpHandle() : base() { } /// protected override bool InternalReleaseHandle() => IcmpCloseHandle(handle); } } }