Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

335 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1991-1999 Microsoft Corporation
  3. Module Name:
  4. icmpapi.h
  5. Abstract:
  6. Declarations for the Win32 ICMP Echo request API.
  7. Author:
  8. Portable Systems Group 30-December-1993
  9. Revision History:
  10. Notes:
  11. --*/
  12. #ifndef _ICMP_INCLUDED_
  13. #define _ICMP_INCLUDED_
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. //
  21. // Exported Routines.
  22. //
  23. //++
  24. //
  25. // Routine Name:
  26. //
  27. // IcmpCreateFile
  28. //
  29. // Routine Description:
  30. //
  31. // Opens a handle on which ICMP Echo Requests can be issued.
  32. //
  33. // Arguments:
  34. //
  35. // None.
  36. //
  37. // Return Value:
  38. //
  39. // An open file handle or INVALID_HANDLE_VALUE. Extended error information
  40. // is available by calling GetLastError().
  41. //
  42. //--
  43. HANDLE
  44. WINAPI
  45. IcmpCreateFile(
  46. VOID
  47. );
  48. //++
  49. //
  50. // Routine Name:
  51. //
  52. // Icmp6CreateFile
  53. //
  54. // Routine Description:
  55. //
  56. // Opens a handle on which ICMPv6 Echo Requests can be issued.
  57. //
  58. // Arguments:
  59. //
  60. // None.
  61. //
  62. // Return Value:
  63. //
  64. // An open file handle or INVALID_HANDLE_VALUE. Extended error information
  65. // is available by calling GetLastError().
  66. //
  67. //--
  68. HANDLE
  69. WINAPI
  70. Icmp6CreateFile(
  71. VOID
  72. );
  73. //++
  74. //
  75. // Routine Name:
  76. //
  77. // IcmpCloseHandle
  78. //
  79. // Routine Description:
  80. //
  81. // Closes a handle opened by ICMPOpenFile.
  82. //
  83. // Arguments:
  84. //
  85. // IcmpHandle - The handle to close.
  86. //
  87. // Return Value:
  88. //
  89. // TRUE if the handle was closed successfully, otherwise FALSE. Extended
  90. // error information is available by calling GetLastError().
  91. //
  92. //--
  93. BOOL
  94. WINAPI
  95. IcmpCloseHandle(
  96. HANDLE IcmpHandle
  97. );
  98. //++
  99. //
  100. // Routine Name:
  101. //
  102. // IcmpSendEcho
  103. //
  104. // Routine Description:
  105. //
  106. // Sends an ICMP Echo request and returns any replies. The
  107. // call returns when the timeout has expired or the reply buffer
  108. // is filled.
  109. //
  110. // Arguments:
  111. //
  112. // IcmpHandle - An open handle returned by ICMPCreateFile.
  113. //
  114. // DestinationAddress - The destination of the echo request.
  115. //
  116. // RequestData - A buffer containing the data to send in the
  117. // request.
  118. //
  119. // RequestSize - The number of bytes in the request data buffer.
  120. //
  121. // RequestOptions - Pointer to the IP header options for the request.
  122. // May be NULL.
  123. //
  124. // ReplyBuffer - A buffer to hold any replies to the request.
  125. // On return, the buffer will contain an array of
  126. // ICMP_ECHO_REPLY structures followed by the
  127. // options and data for the replies. The buffer
  128. // should be large enough to hold at least one
  129. // ICMP_ECHO_REPLY structure plus
  130. // MAX(RequestSize, 8) bytes of data since an ICMP
  131. // error message contains 8 bytes of data.
  132. //
  133. // ReplySize - The size in bytes of the reply buffer.
  134. //
  135. // Timeout - The time in milliseconds to wait for replies.
  136. //
  137. // Return Value:
  138. //
  139. // Returns the number of ICMP_ECHO_REPLY structures stored in ReplyBuffer.
  140. // The status of each reply is contained in the structure. If the return
  141. // value is zero, extended error information is available via
  142. // GetLastError().
  143. //
  144. //--
  145. DWORD
  146. WINAPI
  147. IcmpSendEcho(
  148. HANDLE IcmpHandle,
  149. IPAddr DestinationAddress,
  150. LPVOID RequestData,
  151. WORD RequestSize,
  152. PIP_OPTION_INFORMATION RequestOptions,
  153. LPVOID ReplyBuffer,
  154. DWORD ReplySize,
  155. DWORD Timeout
  156. );
  157. //++
  158. //
  159. // Routine Description:
  160. //
  161. // Sends an ICMP Echo request and the call returns either immediately
  162. // (if Event or ApcRoutine is NonNULL) or returns after the specified
  163. // timeout. The ReplyBuffer contains the ICMP responses, if any.
  164. //
  165. // Arguments:
  166. //
  167. // IcmpHandle - An open handle returned by ICMPCreateFile.
  168. //
  169. // Event - This is the event to be signalled whenever an IcmpResponse
  170. // comes in.
  171. //
  172. // ApcRoutine - This routine would be called when the calling thread
  173. // is in an alertable thread and an ICMP reply comes in.
  174. //
  175. // ApcContext - This optional parameter is given to the ApcRoutine when
  176. // this call succeeds.
  177. //
  178. // DestinationAddress - The destination of the echo request.
  179. //
  180. // RequestData - A buffer containing the data to send in the
  181. // request.
  182. //
  183. // RequestSize - The number of bytes in the request data buffer.
  184. //
  185. // RequestOptions - Pointer to the IP header options for the request.
  186. // May be NULL.
  187. //
  188. // ReplyBuffer - A buffer to hold any replies to the request.
  189. // On return, the buffer will contain an array of
  190. // ICMP_ECHO_REPLY structures followed by options
  191. // and data. The buffer must be large enough to
  192. // hold at least one ICMP_ECHO_REPLY structure.
  193. // It should be large enough to also hold
  194. // 8 more bytes of data - this is the size of
  195. // an ICMP error message.
  196. //
  197. // ReplySize - The size in bytes of the reply buffer.
  198. //
  199. // Timeout - The time in milliseconds to wait for replies.
  200. // This is NOT used if ApcRoutine is not NULL or if Event
  201. // is not NULL.
  202. //
  203. // Return Value:
  204. //
  205. // Returns the number of replies received and stored in ReplyBuffer. If
  206. // the return value is zero, extended error information is available
  207. // via GetLastError().
  208. //
  209. // Remarks:
  210. //
  211. // On NT platforms,
  212. // If used Asynchronously (either ApcRoutine or Event is specified), then
  213. // ReplyBuffer and ReplySize are still needed. This is where the response
  214. // comes in.
  215. // ICMP Response data is copied to the ReplyBuffer provided, and the caller of
  216. // this function has to parse it asynchronously. The function IcmpParseReply
  217. // is provided for this purpose.
  218. //
  219. // On non-NT platforms,
  220. // Event, ApcRoutine and ApcContext are IGNORED.
  221. //
  222. //--
  223. DWORD
  224. WINAPI
  225. IcmpSendEcho2(
  226. HANDLE IcmpHandle,
  227. HANDLE Event,
  228. #ifdef PIO_APC_ROUTINE_DEFINED
  229. PIO_APC_ROUTINE ApcRoutine,
  230. #else
  231. FARPROC ApcRoutine,
  232. #endif
  233. PVOID ApcContext,
  234. IPAddr DestinationAddress,
  235. LPVOID RequestData,
  236. WORD RequestSize,
  237. PIP_OPTION_INFORMATION RequestOptions,
  238. LPVOID ReplyBuffer,
  239. DWORD ReplySize,
  240. DWORD Timeout
  241. );
  242. DWORD
  243. WINAPI
  244. Icmp6SendEcho2(
  245. HANDLE IcmpHandle,
  246. HANDLE Event,
  247. #ifdef PIO_APC_ROUTINE_DEFINED
  248. PIO_APC_ROUTINE ApcRoutine,
  249. #else
  250. FARPROC ApcRoutine,
  251. #endif
  252. PVOID ApcContext,
  253. struct sockaddr_in6 *SourceAddress,
  254. struct sockaddr_in6 *DestinationAddress,
  255. LPVOID RequestData,
  256. WORD RequestSize,
  257. PIP_OPTION_INFORMATION RequestOptions,
  258. LPVOID ReplyBuffer,
  259. DWORD ReplySize,
  260. DWORD Timeout
  261. );
  262. //++
  263. //
  264. // Routine Description:
  265. //
  266. // Parses the reply buffer provided and returns the number of ICMP responses found.
  267. //
  268. // Arguments:
  269. //
  270. // ReplyBuffer - This must be the same buffer that was passed to IcmpSendEcho2
  271. // This is rewritten to hold an array of ICMP_ECHO_REPLY structures.
  272. // (i.e. the type is PICMP_ECHO_REPLY).
  273. //
  274. // ReplySize - This must be the size of the above buffer.
  275. //
  276. // Return Value:
  277. // Returns the number of ICMP responses found. If there is an errors, return value is
  278. // zero. The error can be determined by a call to GetLastError.
  279. //
  280. // Remarks:
  281. // This function SHOULD NOT BE USED on a reply buffer that was passed to SendIcmpEcho.
  282. // SendIcmpEcho actually parses the buffer before returning back to the user. This function
  283. // is meant to be used only with SendIcmpEcho2.
  284. //--
  285. DWORD
  286. IcmpParseReplies(
  287. LPVOID ReplyBuffer,
  288. DWORD ReplySize
  289. );
  290. DWORD
  291. Icmp6ParseReplies(
  292. LPVOID ReplyBuffer,
  293. DWORD ReplySize
  294. );
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298. #endif // _ICMP_INCLUDED_