1 /*
2 * DESCRIPTION: Simple LPC Client
3 * PROGRAMMER: David Welch
4 */
5 #include <ddk/ntddk.h>
6 #include <rosrtl/string.h>
7 #include <windows.h>
8 #include <stdarg.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #include "lpctest.h"
14
15 const char * MyName = "LPC-CLI";
16 HANDLE OutputHandle;
17 HANDLE InputHandle;
18
debug_printf(char * fmt,...)19 void debug_printf(char* fmt, ...)
20 {
21 va_list args;
22 char buffer[255];
23
24 va_start(args,fmt);
25 vsprintf(buffer,fmt,args);
26 WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL);
27 va_end(args);
28 }
29
30
main(int argc,char * argv[])31 int main(int argc, char* argv[])
32 {
33 UNICODE_STRING PortName = ROS_STRING_INITIALIZER(TEST_PORT_NAME_U);
34 NTSTATUS Status;
35 HANDLE PortHandle;
36 LPC_MAX_MESSAGE Request;
37 ULONG ConnectInfo;
38 ULONG ConnectInfoLength = 0;
39 SECURITY_QUALITY_OF_SERVICE Sqos;
40
41 printf("%s: Lpc test client\n", MyName);
42
43 printf("%s: Connecting to port \"%s\"...\n", MyName, TEST_PORT_NAME);
44 ConnectInfoLength = 0;
45 ZeroMemory (& Sqos, sizeof Sqos);
46 Status = NtConnectPort(&PortHandle,
47 &PortName,
48 & Sqos,
49 0,
50 0,
51 0,
52 NULL,
53 &ConnectInfoLength);
54 if (!NT_SUCCESS(Status))
55 {
56 printf("%s: NtConnectPort() failed with status = 0x%08X.\n", MyName, Status);
57 return EXIT_FAILURE;
58 }
59
60 printf("%s: Connected to \"%s\" with anonymous port 0x%x.\n", MyName, TEST_PORT_NAME, PortHandle);
61
62 ZeroMemory(& Request, sizeof Request);
63 strcpy(Request.Data, GetCommandLineA());
64 Request.Header.DataSize = strlen(Request.Data);
65 Request.Header.MessageSize = sizeof(LPC_MESSAGE) +
66 Request.Header.DataSize;
67
68 printf("%s: Sending to port 0x%x message \"%s\"...\n",
69 MyName,
70 PortHandle,
71 (char *) Request.Data);
72 Status = NtRequestPort(PortHandle,
73 &Request.Header);
74 if (!NT_SUCCESS(Status))
75 {
76 printf("%s: NtRequestPort(0x%x) failed with status = 0x%8X.\n",
77 MyName,
78 PortHandle,
79 Status);
80 return EXIT_FAILURE;
81 }
82
83 printf("%s: Sending datagram to port 0x%x succeeded.\n", MyName, PortHandle);
84
85 Sleep(2000);
86
87 printf("%s: Disconnecting...", MyName);
88 NtClose (PortHandle);
89
90 return EXIT_SUCCESS;
91 }
92