ReactOS  0.4.14-dev-49-gfb4591c
send.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: Test for send/sendto
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "ws2_32.h"
9 
10 static
11 PVOID
13  _In_ SIZE_T SizeRequested)
14 {
16  SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
17  PVOID VirtualMemory = NULL;
18 
20  if (!NT_SUCCESS(Status))
21  return NULL;
22 
23  return VirtualMemory;
24 }
25 
26 static
27 VOID
29  _In_ PVOID VirtualMemory)
30 {
32  SIZE_T Size = 0;
33 
35  ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
36 }
37 
38 static
39 VOID
40 test_send(void)
41 {
42  SOCKET sock;
43  int ret;
44  int error;
45  PVOID buffer;
46  ULONG bufferSize;
47  struct sockaddr_in addr;
48 
49  bufferSize = 32;
50  buffer = AllocateReadOnly(bufferSize);
51  ok(buffer != NULL, "AllocateReadOnly failed\n");
52  if (!buffer)
53  {
54  skip("No memory\n");
55  return;
56  }
57 
58  ret = send(0, NULL, 0, 0);
60  ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
61  ok(error == WSAENOTSOCK, "error = %d\n", error);
62 
63  ret = send(0, buffer, bufferSize, 0);
65  ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
66  ok(error == WSAENOTSOCK, "error = %d\n", error);
67 
69  ok(sock != INVALID_SOCKET, "socket failed\n");
70  if (sock == INVALID_SOCKET)
71  {
72  skip("No socket\n");
74  return;
75  }
76 
77  ret = send(sock, NULL, 0, 0);
79  ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
80  ok(error == WSAENOTCONN, "error = %d\n", error);
81 
82  ret = send(sock, buffer, bufferSize, 0);
84  ok(ret == SOCKET_ERROR, "send returned %d\n", ret);
85  ok(error == WSAENOTCONN, "error = %d\n", error);
86 
87  memset(&addr, 0, sizeof(addr));
88  addr.sin_family = AF_INET;
89  addr.sin_addr.s_addr = inet_addr("8.8.8.8");
90  addr.sin_port = htons(53);
91  ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
93  ok(ret == 0, "connect returned %d\n", ret);
94  ok(error == 0, "error = %d\n", error);
95 
96  ret = send(sock, NULL, 0, 0);
98  ok(ret == 0, "send returned %d\n", ret);
99  ok(error == 0, "error = %d\n", error);
100 
101  ret = send(sock, buffer, bufferSize, 0);
103  ok(ret == bufferSize, "send returned %d\n", ret);
104  ok(error == 0, "error = %d\n", error);
105 
106  closesocket(sock);
107 
109 }
110 
111 static
112 VOID
114 {
115  SOCKET sock;
116  int ret;
117  int error;
118  PVOID buffer;
119  ULONG bufferSize;
120  struct sockaddr_in addr;
121 
122  bufferSize = 32;
123  buffer = AllocateReadOnly(bufferSize);
124  ok(buffer != NULL, "AllocateReadOnly failed\n");
125  if (!buffer)
126  {
127  skip("No memory\n");
128  return;
129  }
130 
131  memset(&addr, 0, sizeof(addr));
132  addr.sin_family = AF_INET;
133  addr.sin_addr.s_addr = inet_addr("8.8.8.8");
134  addr.sin_port = htons(53);
135 
136  ret = sendto(0, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
138  ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
139  ok(error == WSAENOTSOCK, "error = %d\n", error);
140 
141  ret = sendto(0, buffer, bufferSize, 0, (const struct sockaddr *)&addr, sizeof(addr));
143  ok(ret == SOCKET_ERROR, "sendto returned %d\n", ret);
144  ok(error == WSAENOTSOCK, "error = %d\n", error);
145 
147  ok(sock != INVALID_SOCKET, "socket failed\n");
148  if (sock == INVALID_SOCKET)
149  {
150  skip("No socket\n");
152  return;
153  }
154 
155  ret = sendto(sock, NULL, 0, 0, (const struct sockaddr *)&addr, sizeof(addr));
157  ok(ret == 0, "sendto returned %d\n", ret);
158  ok(error == 0, "error = %d\n", error);
159 
160  ret = sendto(sock, buffer, bufferSize, 0, (const struct sockaddr *)&addr, sizeof(addr));
162  ok(ret == bufferSize, "sendto returned %d\n", ret);
163  ok(error == 0, "error = %d\n", error);
164 
165  closesocket(sock);
166 
168 }
169 
171 {
172  int ret;
173  WSADATA wsad;
174 
175  ret = WSAStartup(MAKEWORD(2, 2), &wsad);
176  ok(ret == 0, "WSAStartup failed with %d\n", ret);
177  test_send();
178  test_sendto();
179  WSACleanup();
180 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
static SOCKET sock
Definition: syslog.c:45
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define inet_addr(cp)
Definition: inet.h:98
#define error(str)
Definition: mkdosfs.c:1605
#define MAKEWORD(a, b)
Definition: typedefs.h:247
LONG NTSTATUS
Definition: precomp.h:26
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
GLuint buffer
Definition: glext.h:5915
static VOID FreeReadOnly(_In_ PVOID VirtualMemory)
Definition: send.c:28
#define MEM_COMMIT
Definition: nt_native.h:1313
static VOID test_sendto(void)
Definition: send.c:113
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
#define closesocket
Definition: main.c:39
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
int ret
GLenum const GLvoid * addr
Definition: glext.h:9621
#define WSAENOTCONN
Definition: winerror.h:1970
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
START_TEST(send)
Definition: send.c:91
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4367
#define ok(value,...)
Definition: atltest.h:57
#define PAGE_READONLY
Definition: compat.h:127
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
Definition: tcpcore.h:1455
#define skip(...)
Definition: atltest.h:64
#define MEM_RELEASE
Definition: nt_native.h:1316
static VOID test_send(void)
Definition: send.c:40
unsigned int ULONG
Definition: retypes.h:1
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
#define htons(x)
Definition: module.h:213
#define SOCK_DGRAM
Definition: winsock.h:336
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PVOID AllocateReadOnly(_In_ SIZE_T SizeRequested)
Definition: send.c:12
#define memset(x, y, z)
Definition: compat.h:39
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5090