Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
[Samba/bb.git] / testprogs / win32 / npecho / npecho_client.c
blob97d31c4318444362c8d40ec93fa3ff928a0033c4
1 /*
2 * Simple Named Pipe Client
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 * Published to the public domain
5 */
7 #include <windows.h>
8 #include <stdio.h>
10 #define ECHODATA "Black Dog"
12 int main(int argc, char *argv[])
14 HANDLE h;
15 DWORD numread = 0;
16 char *outbuffer = malloc(strlen(ECHODATA));
18 if (argc == 1) {
19 printf("Usage: %s pipename\n", argv[0]);
20 printf(" Where pipename is something like \\\\servername\\NPECHO\n");
21 return -1;
24 h = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
25 if (h == INVALID_HANDLE_VALUE) {
26 printf("Error opening: %d\n", GetLastError());
27 return -1;
30 if (!WriteFile(h, ECHODATA, strlen(ECHODATA), &numread, NULL)) {
31 printf("Error writing: %d\n", GetLastError());
32 return -1;
35 if (!ReadFile(h, outbuffer, strlen(ECHODATA), &numread, NULL)) {
36 printf("Error reading: %d\n", GetLastError());
37 return -1;
40 printf("Read: %s\n", outbuffer);
42 if (!TransactNamedPipe(h, ECHODATA, strlen(ECHODATA), outbuffer, strlen(ECHODATA), &numread, NULL)) {
43 printf("TransactNamedPipe failed: %d!\n", GetLastError());
44 return -1;
47 printf("Result: %s\n", outbuffer);
49 return 0;