ReactOS 0.4.15-dev-8127-g6338913
icmp.c File Reference
#include <apitest.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <icmpapi.h>
Include dependency graph for icmp.c:

Go to the source code of this file.

Functions

static void test_IcmpCreateFile (void)
 
static void test_Icmp6CreateFile (void)
 
static void test_IcmpCloseHandle (void)
 
static void test_IcmpSendEcho (void)
 
 START_TEST (icmp)
 

Function Documentation

◆ START_TEST()

START_TEST ( icmp  )

Definition at line 129 of file icmp.c.

130{
135}
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

◆ test_Icmp6CreateFile()

static void test_Icmp6CreateFile ( void  )
static

Definition at line 29 of file icmp.c.

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}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI IcmpCloseHandle(_In_ HANDLE IcmpHandle)
Definition: icmp.c:202
HANDLE WINAPI Icmp6CreateFile(void)
Definition: icmp.c:15
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ test_IcmpCloseHandle()

static void test_IcmpCloseHandle ( void  )
static

Definition at line 51 of file icmp.c.

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}
#define ok_err(error)
Definition: atltest.h:124
#define NULL
Definition: types.h:112
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
HANDLE WINAPI IcmpCreateFile(void)
Definition: icmp.c:219
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by START_TEST().

◆ test_IcmpCreateFile()

static void test_IcmpCreateFile ( void  )
static

Definition at line 15 of file icmp.c.

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}

Referenced by START_TEST().

◆ test_IcmpSendEcho()

static void test_IcmpSendEcho ( void  )
static

Definition at line 87 of file icmp.c.

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}
#define INADDR_NONE
Definition: tcp.c:42
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
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 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
static BOOL SendData(PINFO pInfo)
Definition: ntpclient.c:76

Referenced by START_TEST().