72edb020045882708d089d2522907fc6abade19b
[samba.git] / testprogs / win32 / npecho / npecho_server2.c
1 /*
2  * Simple Named Pipe Client
3  * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4  * (C) 2009 Stefan Metzmacher <metze@samba.org>
5  * Published to the public domain
6  */
7
8 #include <windows.h>
9 #include <stdio.h>
10
11 #define ECHODATA "Black Dog"
12
13 int main(int argc, char *argv[])
14 {
15         HANDLE h;
16         DWORD numread = 0;
17         char *outbuffer = malloc(sizeof(ECHODATA));
18
19         if (argc == 1) {
20                 printf("Usage: %s pipename\n", argv[0]);
21                 printf("  Where pipename is something like \\\\servername\\NPECHO\n");
22                 return -1;
23         }
24
25         h = CreateNamedPipe(argv[1],
26                             PIPE_ACCESS_DUPLEX,
27                             PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
28                             PIPE_UNLIMITED_INSTANCES,
29                             1024,
30                             1024,
31                             0,
32                             NULL);
33         if (h == INVALID_HANDLE_VALUE) {
34                 printf("Error opening: %d\n", GetLastError());
35                 return -1;
36         }
37
38         ConnectNamedPipe(h, NULL);
39
40         if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
41                 printf("Error writing: %d\n", GetLastError());
42                 return -1;
43         }
44
45         if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
46                 printf("Error writing: %d\n", GetLastError());
47                 return -1;
48         }
49
50         FlushFileBuffers(h);
51         DisconnectNamedPipe(h);
52         CloseHandle(h);
53
54         return 0;
55 }