ReactOS  0.4.14-dev-599-g2d4d3f5
send.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API Tests
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: Test for IOCTL_AFD_SEND/IOCTL_AFD_SEND_DATAGRAM
5  * COPYRIGHT: Copyright 2015 Thomas Faber (thomas.faber@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 static
11 void
12 TestSend(void)
13 {
15  HANDLE SocketHandle;
16  CHAR Buffer[32];
17  struct sockaddr_in addr;
18 
19  RtlZeroMemory(Buffer, sizeof(Buffer));
20 
22  ok(Status == STATUS_SUCCESS, "AfdCreateSocket failed with %lx\n", Status);
23 
24  Status = AfdSend(SocketHandle, NULL, 0);
25  ok(Status == STATUS_INVALID_CONNECTION, "AfdSend failed with %lx\n", Status);
26 
27  Status = AfdSend(SocketHandle, Buffer, sizeof(Buffer));
28  ok(Status == STATUS_INVALID_CONNECTION, "AfdSend failed with %lx\n", Status);
29 
30  memset(&addr, 0, sizeof(addr));
31  addr.sin_family = AF_INET;
32  addr.sin_addr.s_addr = inet_addr("0.0.0.0");
33  addr.sin_port = htons(0);
34 
35  Status = AfdBind(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
36  ok(Status == STATUS_SUCCESS, "AfdBind failed with %lx\n", Status);
37 
38  memset(&addr, 0, sizeof(addr));
39  addr.sin_family = AF_INET;
40  addr.sin_addr.s_addr = inet_addr("8.8.8.8");
41  addr.sin_port = htons(53);
42 
43  Status = AfdConnect(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
44  ok(Status == STATUS_SUCCESS, "AfdConnect failed with %lx\n", Status);
45 
46  Status = AfdSend(SocketHandle, NULL, 0);
47  ok(Status == STATUS_SUCCESS, "AfdSend failed with %lx\n", Status);
48 
49  Status = AfdSend(SocketHandle, Buffer, sizeof(Buffer));
50  ok(Status == STATUS_SUCCESS, "AfdSend failed with %lx\n", Status);
51 
52  NtClose(SocketHandle);
53 }
54 
55 static
56 void
58 {
60  HANDLE SocketHandle;
61  CHAR Buffer[32];
62  struct sockaddr_in addr;
63 
64  RtlZeroMemory(Buffer, sizeof(Buffer));
65 
67  ok(Status == STATUS_SUCCESS, "AfdCreateSocket failed with %lx\n", Status);
68 
69  memset(&addr, 0, sizeof(addr));
70  addr.sin_family = AF_INET;
71  addr.sin_addr.s_addr = inet_addr("0.0.0.0");
72  addr.sin_port = htons(0);
73 
74  Status = AfdBind(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
75  ok(Status == STATUS_SUCCESS, "AfdBind failed with %lx\n", Status);
76 
77  memset(&addr, 0, sizeof(addr));
78  addr.sin_family = AF_INET;
79  addr.sin_addr.s_addr = inet_addr("8.8.8.8");
80  addr.sin_port = htons(53);
81 
82  Status = AfdSendTo(SocketHandle, NULL, 0, (const struct sockaddr *)&addr, sizeof(addr));
83  ok(Status == STATUS_SUCCESS, "AfdSendTo failed with %lx\n", Status);
84 
85  Status = AfdSendTo(SocketHandle, Buffer, sizeof(Buffer), (const struct sockaddr *)&addr, sizeof(addr));
86  ok(Status == STATUS_SUCCESS, "AfdSendTo failed with %lx\n", Status);
87 
88  NtClose(SocketHandle);
89 }
90 
92 {
93  TestSend();
94  TestSendTo();
95 }
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:542
#define inet_addr(cp)
Definition: inet.h:98
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS AfdSend(_In_ HANDLE SocketHandle, _In_ const void *Buffer, _In_ ULONG BufferLength)
Definition: AfdHelpers.c:264
NTSTATUS AfdSendTo(_In_ HANDLE SocketHandle, _In_ const void *Buffer, _In_ ULONG BufferLength, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:314
static void TestSend(void)
Definition: send.c:12
static void TestSendTo(void)
Definition: send.c:57
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
NTSTATUS AfdBind(_In_ HANDLE SocketHandle, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:134
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
static NTSTATUS NTAPI AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: main.c:302
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
NTSTATUS AfdConnect(_In_ HANDLE SocketHandle, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:197
GLenum const GLvoid * addr
Definition: glext.h:9621
START_TEST(send)
Definition: send.c:91
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
#define AF_INET
Definition: tcpip.h:117
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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:2938
#define memset(x, y, z)
Definition: compat.h:39