Named pipe communication headers.
More...
Go to the source code of this file.
|
HANDLE | NamedPipeServerCreatePipe (LPCSTR PipeName, UINT32 OutputBufferSize, UINT32 InputBufferSize) |
| Create a named pipe server.
|
|
BOOLEAN | NamedPipeServerWaitForClientConntection (HANDLE PipeHandle) |
| wait for client connection
|
|
UINT32 | NamedPipeServerReadClientMessage (HANDLE PipeHandle, char *BufferToSave, int MaximumReadBufferLength) |
| read client message from the named pipe
|
|
BOOLEAN | NamedPipeServerSendMessageToClient (HANDLE PipeHandle, char *BufferToSend, int BufferSize) |
|
VOID | NamedPipeServerCloseHandle (HANDLE PipeHandle) |
| Close handle of server's named pipe.
|
|
HANDLE | NamedPipeClientCreatePipe (LPCSTR PipeName) |
| Create a client named pipe.
|
|
BOOLEAN | NamedPipeClientSendMessage (HANDLE PipeHandle, char *BufferToSend, int BufferSize) |
| send client message over named pipe
|
|
UINT32 | NamedPipeClientReadMessage (HANDLE PipeHandle, char *BufferToRead, int MaximumSizeOfBuffer) |
|
VOID | NamedPipeClientClosePipe (HANDLE PipeHandle) |
| close named pipe handle of client
|
|
Named pipe communication headers.
- Author
- Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
- Version
- 0.1
- Date
- 2020-04-11
- Copyright
- This project is released under the GNU Public License v3.
◆ NamedPipeClientClosePipe()
VOID NamedPipeClientClosePipe |
( |
HANDLE | PipeHandle | ) |
|
close named pipe handle of client
- Parameters
-
- Returns
- VOID
303{
304 CloseHandle(PipeHandle);
305}
◆ NamedPipeClientCreatePipe()
HANDLE NamedPipeClientCreatePipe |
( |
LPCSTR | PipeName | ) |
|
Create a client named pipe.
Pipe name format - \servername\pipe\pipename This pipe is for server on the same computer, however, pipes can be used to connect to a remote server
- Parameters
-
- Returns
- HANDLE
180{
181 HANDLE hPipe;
182
183
184
185
186 hPipe = CreateFileA(PipeName,
187 GENERIC_READ |
188 GENERIC_WRITE,
189 0,
190 NULL,
191 OPEN_EXISTING,
192 0,
193 NULL);
194
195 if (INVALID_HANDLE_VALUE == hPipe)
196 {
197 printf("err, occurred while connecting to the server (%x)\n",
198 GetLastError());
199
200
201
202
203
204
205
206
207
209 }
210 else
211 {
212 return hPipe;
213 }
214}
NULL()
Definition test-case-generator.py:530
◆ NamedPipeClientReadMessage()
UINT32 NamedPipeClientReadMessage |
( |
HANDLE | PipeHandle, |
|
|
char * | BufferToRead, |
|
|
int | MaximumSizeOfBuffer ) |
269{
271
272
273
274
275 BOOL bResult = ReadFile(PipeHandle,
276 BufferToRead,
277 MaximumSizeOfBuffer,
278 &cbBytes,
279 NULL);
280
281 if ((!bResult) || (0 == cbBytes))
282 {
283 printf("err, occurred while reading from the server (%x)\n",
284 GetLastError());
285 CloseHandle(PipeHandle);
287 }
288
289
290
291
292 return cbBytes;
293}
int BOOL
Definition BasicTypes.h:23
unsigned long DWORD
Definition BasicTypes.h:22
◆ NamedPipeClientSendMessage()
BOOLEAN NamedPipeClientSendMessage |
( |
HANDLE | PipeHandle, |
|
|
char * | BufferToSend, |
|
|
int | BufferSize ) |
send client message over named pipe
- Parameters
-
PipeHandle | |
BufferToSend | |
BufferSize | |
- Returns
- BOOLEAN
226{
227
228
229
230
231
232
233
235
236
237
238
240 WriteFile(PipeHandle,
241 BufferToSend,
242 BufferSize,
243 &cbBytes,
244 NULL);
245
246 if ((!bResult) || (BufferSize != cbBytes))
247 {
248 printf("err, occurred while writing to the server (%x)\n",
249 GetLastError());
250 CloseHandle(PipeHandle);
251
252
253
254
255 CloseHandle(PipeHandle);
257 }
258 else
259 {
261 }
262}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
◆ NamedPipeServerCloseHandle()
VOID NamedPipeServerCloseHandle |
( |
HANDLE | PipeHandle | ) |
|
Close handle of server's named pipe.
- Parameters
-
- Returns
- VOID
157{
158 CloseHandle(PipeHandle);
159}
◆ NamedPipeServerCreatePipe()
HANDLE NamedPipeServerCreatePipe |
( |
LPCSTR | PipeName, |
|
|
UINT32 | OutputBufferSize, |
|
|
UINT32 | InputBufferSize ) |
Create a named pipe server.
- Parameters
-
PipeName | |
OutputBufferSize | |
InputBufferSize | |
- Returns
- HANDLE
28{
29 HANDLE hPipe;
30
31 hPipe = CreateNamedPipeA(PipeName,
32 PIPE_ACCESS_DUPLEX,
33 PIPE_TYPE_MESSAGE |
34 PIPE_READMODE_MESSAGE |
35 PIPE_WAIT,
36 PIPE_UNLIMITED_INSTANCES,
37 OutputBufferSize,
38 InputBufferSize,
39 NMPWAIT_USE_DEFAULT_WAIT,
40 NULL);
41
42 if (INVALID_HANDLE_VALUE == hPipe)
43 {
44 printf("err, occurred while creating the pipe (%x)\n",
45 GetLastError());
47 }
48 return hPipe;
49}
◆ NamedPipeServerReadClientMessage()
UINT32 NamedPipeServerReadClientMessage |
( |
HANDLE | PipeHandle, |
|
|
char * | BufferToSave, |
|
|
int | MaximumReadBufferLength ) |
read client message from the named pipe
- Parameters
-
PipeHandle | |
BufferToSave | |
MaximumReadBufferLength | |
- Returns
- UINT32
89{
91
92
93
94
95
96
97
98
99
100
101
102 BOOL bResult = ReadFile(PipeHandle,
103 BufferToSave,
104 MaximumReadBufferLength,
105 &cbBytes,
106 NULL);
107
108 if ((!bResult) || (0 == cbBytes))
109 {
110 printf("err, occurred while reading from the client (%x)\n",
111 GetLastError());
112 CloseHandle(PipeHandle);
113 return 0;
114 }
115
116
117
118
119 return cbBytes;
120}
◆ NamedPipeServerSendMessageToClient()
BOOLEAN NamedPipeServerSendMessageToClient |
( |
HANDLE | PipeHandle, |
|
|
char * | BufferToSend, |
|
|
int | BufferSize ) |
126{
128
129
130
131
133 WriteFile(PipeHandle,
134 BufferToSend,
135 BufferSize,
136 &cbBytes,
137 NULL);
138
139 if ((!bResult) || (BufferSize != cbBytes))
140 {
141 printf("Error occurred while writing to the client (%x)\n",
142 GetLastError());
143 CloseHandle(PipeHandle);
145 }
147}
UCHAR BOOLEAN
Definition BasicTypes.h:39
◆ NamedPipeServerWaitForClientConntection()
BOOLEAN NamedPipeServerWaitForClientConntection |
( |
HANDLE | PipeHandle | ) |
|
wait for client connection
- Parameters
-
- Returns
- BOOLEAN
59{
60
61
62
63 BOOL bClientConnected = ConnectNamedPipe(PipeHandle, NULL);
64
65 if (
FALSE == bClientConnected)
66 {
67 printf("err, occurred while connecting to the client (%x)\n",
68 GetLastError());
69 CloseHandle(PipeHandle);
71 }
72
73
74
75
77}