testprogs/win32: add npecho_*2.c
[kai/samba-autobuild/.git] / testprogs / win32 / npecho / npecho_client2.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)*2);
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 = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
26         if (h == INVALID_HANDLE_VALUE) {
27                 printf("Error opening: %d\n", GetLastError());
28                 return -1;
29         }
30
31         Sleep(1000);
32
33         if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
34                 printf("Error reading: %d\n", GetLastError());
35                 return -1;
36         }
37
38         printf("Read: %s %d\n", outbuffer, numread);
39
40         if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
41                 printf("Error reading: %d\n", GetLastError());
42                 return -1;
43         }
44
45         printf("Read: %s %d\n", outbuffer, numread);
46
47         return 0;
48 }