ReactOS  0.4.15-dev-494-g1d8c567
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 {
22  va_list args;
23  char buffer[255];
24 
25  va_start(args,fmt);
28  va_end(args);
29 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint buffer
Definition: glext.h:5915
HANDLE OutputHandle
Definition: lpcsrv.c:17
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
Definition: dsound.c:943

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

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 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
smooth NULL
Definition: ftsmooth.c:416
#define TEST_PORT_NAME
Definition: lpctest.h:3
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 NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:212
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXIT_FAILURE
Definition: jerror.c:33
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
Status
Definition: gdiplustypes.h:24
#define TEST_PORT_NAME_U
Definition: lpctest.h:4
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:421
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static const char * MyName
Definition: lpcsrv.c:15
NTSTATUS NTAPI NtListenPort(IN HANDLE PortHandle, OUT PPORT_MESSAGE ConnectMessage)
Definition: listen.c:22
#define printf
Definition: config.h:203
IN PUNICODE_STRING PortName
Definition: conport.c:35

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().