ReactOS 0.4.15-dev-7924-g5949c20
lpcsrv.c File Reference
#include <ddk/ntddk.h>
#include <rosrtl/string.h>
#include <windows.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "lpctest.h"
Include dependency graph for lpcsrv.c:

Go to the source code of this file.

Functions

void debug_printf (char *fmt,...)
 
int main (int argc, char *argv[])
 

Variables

static const charMyName = "LPC-SRV"
 
HANDLE OutputHandle
 
HANDLE InputHandle
 

Function Documentation

◆ debug_printf()

void debug_printf ( char fmt,
  ... 
)

Definition at line 20 of file lpcsrv.c.

21{
23 char buffer[255];
24
28 va_end(args);
29}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define NULL
Definition: types.h:112
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
GLuint buffer
Definition: glext.h:5915
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
HANDLE OutputHandle
Definition: lpcsrv.c:17
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 32 of file lpcsrv.c.

33{
34 UNICODE_STRING PortName = ROS_STRING_INITIALIZER(TEST_PORT_NAME_U);
37 HANDLE NamedPortHandle;
38 HANDLE PortHandle;
39 LPC_MAX_MESSAGE ConnectMsg;
40
41 printf("%s: Lpc test server\n", MyName);
42
44 &PortName,
45 0,
46 NULL,
47 NULL);
48
49 printf("%s: Creating port \"%s\"...\n", MyName, TEST_PORT_NAME);
50 Status = NtCreatePort(&NamedPortHandle,
52 0,
53 0,
54 0);
55 if (!NT_SUCCESS(Status))
56 {
57 printf("%s: NtCreatePort() failed with status = 0x%08lX.\n", MyName, Status);
58 return EXIT_FAILURE;
59 }
60 printf("%s: Port \"%s\" created (0x%x).\n\n", MyName, TEST_PORT_NAME, NamedPortHandle);
61
62 for (;;)
63 {
64 printf("%s: Listening for connections requests on port 0x%x...\n", MyName, NamedPortHandle);
65 Status = NtListenPort(NamedPortHandle,
66 &ConnectMsg.Header);
67 if (!NT_SUCCESS(Status))
68 {
69 printf("%s: NtListenPort() failed with status = 0x%08lX.\n", MyName, Status);
70 return EXIT_FAILURE;
71 }
72
73 printf("%s: Received connection request 0x%08x on port 0x%x.\n", MyName,
74 ConnectMsg.Header.MessageId, NamedPortHandle);
75 printf("%s: Request from: PID=%x, TID=%x.\n", MyName,
76 ConnectMsg.Header.ClientId.UniqueProcess, ConnectMsg.Header.ClientId.UniqueThread);
77
78 printf("%s: Accepting connection request 0x%08x...\n", MyName,
79 ConnectMsg.Header.MessageId);
80 Status = NtAcceptConnectPort(&PortHandle,
81 NamedPortHandle,
82 & ConnectMsg.Header,
83 TRUE,
84 0,
85 NULL);
86 if (!NT_SUCCESS(Status))
87 {
88 printf("%s: NtAcceptConnectPort() failed with status = 0x%08lX.\n", MyName, Status);
89 return EXIT_FAILURE;
90 }
91 printf("%s: Connection request 0x%08x accepted as port 0x%x.\n", MyName,
92 ConnectMsg.Header.MessageId, PortHandle);
93
94 printf("%s: Completing connection for port 0x%x (0x%08x).\n", MyName,
95 PortHandle, ConnectMsg.Header.MessageId);
96 Status = NtCompleteConnectPort(PortHandle);
97 if (!NT_SUCCESS(Status))
98 {
99 printf("%s: NtCompleteConnectPort() failed with status = 0x%08lX.\n", MyName, Status);
100 return EXIT_FAILURE;
101 }
102
103 printf("%s: Entering server loop for port 0x%x...\n", MyName, PortHandle);
104 for(;;)
105 {
106 LPC_MAX_MESSAGE Request;
107
108 Status = NtReplyWaitReceivePort(PortHandle,
109 0,
110 NULL,
111 &Request.Header);
112 if (!NT_SUCCESS(Status))
113 {
114 printf("%s: NtReplyWaitReceivePort() failed with status = 0x%08lX.\n", MyName, Status);
115 return EXIT_FAILURE;
116 }
117
118 if (LPC_DATAGRAM == PORT_MESSAGE_TYPE(Request))
119 {
120 printf("%s: Datagram message contents are <%s>.\n",
121 MyName,
122 Request.Data);
123 }
124 else
125 {
126 printf("%s: Message with type %d received on port 0x%x.\n", MyName,
127 PORT_MESSAGE_TYPE(Request), PortHandle);
128 NtClose(PortHandle);
129 printf("%s: Connected port 0x%x closed.\n\n", MyName, PortHandle);
130 break;
131 }
132 }
133 }
134 return EXIT_SUCCESS;
135}
static UNICODE_STRING PortName
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define printf
Definition: freeldr.h:93
Status
Definition: gdiplustypes.h:25
#define EXIT_FAILURE
Definition: jerror.c:33
static const char * MyName
Definition: lpcsrv.c:15
#define TEST_PORT_NAME
Definition: lpctest.h:3
#define TEST_PORT_NAME_U
Definition: lpctest.h:4
#define LPC_DATAGRAM
Definition: port.c:95
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:222
NTSTATUS NTAPI NtListenPort(IN HANDLE PortHandle, OUT PPORT_MESSAGE ConnectMessage)
Definition: listen.c:22
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Variable Documentation

◆ InputHandle

HANDLE InputHandle

Definition at line 18 of file lpcsrv.c.

◆ MyName

const char* MyName = "LPC-SRV"
static

Definition at line 15 of file lpcsrv.c.

Referenced by main().

◆ OutputHandle

HANDLE OutputHandle

Definition at line 17 of file lpcsrv.c.

Referenced by debug_printf().