ReactOS 0.4.15-dev-5666-gc548b97
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
10static
11void
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
55static
56void
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}
NTSTATUS AfdBind(_In_ HANDLE SocketHandle, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:134
NTSTATUS AfdSendTo(_In_ HANDLE SocketHandle, _In_ const void *Buffer, _In_ ULONG BufferLength, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:314
NTSTATUS AfdSend(_In_ HANDLE SocketHandle, _In_ const void *Buffer, _In_ ULONG BufferLength)
Definition: AfdHelpers.c:264
NTSTATUS AfdConnect(_In_ HANDLE SocketHandle, _In_ const struct sockaddr *Address, _In_ ULONG AddressLength)
Definition: AfdHelpers.c:197
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
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
#define IPPROTO_TCP
Definition: ip.h:196
#define IPPROTO_UDP
Definition: ip.h:197
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
Status
Definition: gdiplustypes.h:25
GLenum const GLvoid * addr
Definition: glext.h:9621
#define inet_addr(cp)
Definition: inet.h:98
#define htons(x)
Definition: module.h:213
static void TestSend(void)
Definition: send.c:12
static void TestSendTo(void)
Definition: send.c:57
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:556
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define SOCK_DGRAM
Definition: winsock.h:336
char CHAR
Definition: xmlstorage.h:175