ReactOS 0.4.16-dev-136-g52192f1
icmp.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Tests for ICMP functions
5 * PROGRAMMERS: Tim Crawford
6 */
7
8#include <apitest.h>
9#include <ws2tcpip.h>
10#include <iphlpapi.h>
11#include <icmpapi.h>
12
13static
14void
16{
17 HANDLE hIcmp;
18
19 SetLastError(0xDEADBEEF);
20 hIcmp = IcmpCreateFile();
21 ok(hIcmp != INVALID_HANDLE_VALUE, "IcmpCreateFile failed unexpectedly: %lu\n", GetLastError());
22
23 if (hIcmp != INVALID_HANDLE_VALUE)
24 IcmpCloseHandle(hIcmp);
25}
26
27static
28void
30{
31 HANDLE hIcmp;
32
33 SetLastError(0xDEADBEEF);
34 hIcmp = Icmp6CreateFile();
35
37 {
38 /* On Windows Server 2003, the IPv6 protocol must be installed. */
39 skip("IPv6 is not available.\n");
40 return;
41 }
42
43 ok(hIcmp != INVALID_HANDLE_VALUE, "Icmp6CreateFile failed unexpectedly: %lu\n", GetLastError());
44
45 if (hIcmp != INVALID_HANDLE_VALUE)
46 IcmpCloseHandle(hIcmp);
47}
48
49static
50void
52{
53 HANDLE hIcmp;
54 BOOL bRet;
55
56 SetLastError(0xDEADBEEF);
57 hIcmp = IcmpCreateFile();
58 if (hIcmp != INVALID_HANDLE_VALUE)
59 {
60 bRet = IcmpCloseHandle(hIcmp);
61 ok(bRet, "IcmpCloseHandle failed unexpectedly: %lu\n", GetLastError());
62 }
63
64 SetLastError(0xDEADBEEF);
65 hIcmp = Icmp6CreateFile();
66 if (hIcmp != INVALID_HANDLE_VALUE)
67 {
68 bRet = IcmpCloseHandle(hIcmp);
69 ok(bRet, "IcmpCloseHandle failed unexpectedly: %lu\n", GetLastError());
70 }
71
73 SetLastError(0xDEADBEEF);
74 bRet = IcmpCloseHandle(hIcmp);
75 ok(!bRet, "IcmpCloseHandle succeeded unexpectedly\n");
77
78 hIcmp = NULL;
79 SetLastError(0xDEADBEEF);
80 bRet = IcmpCloseHandle(hIcmp);
81 ok(!bRet, "IcmpCloseHandle succeeded unexpectedly\n");
83}
84
85static
86void
88{
89 HANDLE hIcmp;
90 unsigned long ipaddr = INADDR_NONE;
91 DWORD bRet = 0, error = 0;
92 char SendData[32] = "Data Buffer";
94 DWORD ReplySize = 0;
95
96 SetLastError(0xDEADBEEF);
97 hIcmp = IcmpCreateFile();
98 if (hIcmp == INVALID_HANDLE_VALUE)
99 {
100 skip("IcmpCreateFile failed unexpectedly: %lu\n", GetLastError());
101 return;
102 }
103
104 ipaddr = 0x08080808; // 8.8.8.8
105 ReplyBuffer = malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
106
107 ReplySize = sizeof(ICMP_ECHO_REPLY);
108 SetLastError(0xDEADBEEF);
109 bRet = IcmpSendEcho(hIcmp, ipaddr, SendData, sizeof(SendData),
110 NULL, ReplyBuffer, ReplySize, 5000);
111
112 ok(!bRet, "IcmpSendEcho succeeded unexpectedly\n");
114 ok(error == IP_BUF_TOO_SMALL /* Win2003 */ ||
115 error == IP_GENERAL_FAILURE /* Win10 */,
116 "IcmpSendEcho returned unexpected error: %lu\n", error);
117
118 ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
119 SetLastError(0xDEADBEEF);
120 bRet = IcmpSendEcho(hIcmp, ipaddr, SendData, sizeof(SendData),
121 NULL, ReplyBuffer, ReplySize, 5000);
122
123 ok(bRet, "IcmpSendEcho failed unexpectedly: %lu\n", GetLastError());
124
126 IcmpCloseHandle(hIcmp);
127}
128
130{
135}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ok_err(error)
Definition: atltest.h:124
#define START_TEST(x)
Definition: atltest.h:75
#define INADDR_NONE
Definition: tcp.c:42
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI IcmpCloseHandle(_In_ HANDLE IcmpHandle)
Definition: icmp.c:202
HANDLE WINAPI Icmp6CreateFile(void)
Definition: icmp.c:15
HANDLE WINAPI IcmpCreateFile(void)
Definition: icmp.c:219
DWORD WINAPI IcmpSendEcho(_In_ HANDLE IcmpHandle, _In_ IPAddr DestinationAddress, _In_ LPVOID RequestData, _In_ WORD RequestSize, _In_opt_ PIP_OPTION_INFORMATION RequestOptions, _Out_ LPVOID ReplyBuffer, _In_ DWORD ReplySize, _In_ DWORD Timeout)
Definition: icmp.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1902
#define IP_BUF_TOO_SMALL
Definition: ipexport.h:114
struct icmp_echo_reply ICMP_ECHO_REPLY
#define IP_GENERAL_FAILURE
Definition: ipexport.h:138
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static void test_Icmp6CreateFile(void)
Definition: icmp.c:29
static void test_IcmpSendEcho(void)
Definition: icmp.c:87
static void test_IcmpCloseHandle(void)
Definition: icmp.c:51
static void test_IcmpCreateFile(void)
Definition: icmp.c:15
static BOOL SendData(PINFO pInfo)
Definition: ntpclient.c:76
Definition: ip_icmp.h:52
DWORD WINAPI GetLastError(void)
Definition: except.c:1042