npecho tests
authorStefan Metzmacher <metze@samba.org>
Fri, 4 Sep 2009 13:40:46 +0000 (15:40 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Apr 2013 09:26:22 +0000 (11:26 +0200)
testprogs/win32/npecho/npecho_client_64k.c [new file with mode: 0644]

diff --git a/testprogs/win32/npecho/npecho_client_64k.c b/testprogs/win32/npecho/npecho_client_64k.c
new file mode 100644 (file)
index 0000000..be0ce09
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define NPECHO_CMD_SLEEP 0
+#define NPECHO_CMD_READ 1
+#define NPECHO_CMD_WRITE 2
+#define NPECHO_CMD_NEXT_CTRL 3
+
+int main(int argc, char *argv[])
+{
+       HANDLE h;
+       DWORD numio = 0;
+       char buf[0xFFFF];
+       DWORD i;
+       struct {
+               DWORD cmd;
+               DWORD val;
+       } cmds[256];
+       DWORD num_cmds = 0;
+       char errbuf[4];
+
+       cmds[0].cmd = NPECHO_CMD_READ;
+       cmds[0].val = 0xFFFF;
+       cmds[1].cmd = NPECHO_CMD_WRITE;
+       cmds[1].val = 0xFFFF;
+       cmds[2].cmd = NPECHO_CMD_READ;
+       cmds[2].val = 0xFFFF;
+       cmds[3].cmd = NPECHO_CMD_WRITE;
+       cmds[4].val = 0xFFFF;
+       num_cmds = 4;
+
+       for (i=0; i < sizeof(buf); i++) {
+               buf[i] = i & 0xFF;
+       }
+
+       if (argc == 1) {
+               printf("Usage: %s pipename\n", argv[0]);
+               printf("  Where pipename is something like \\\\servername\\NPECHO\n");
+               return -1;
+       }
+
+       h = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+       if (h == INVALID_HANDLE_VALUE) {
+               printf("Error opening: %d\n", GetLastError());
+               return -1;
+       }
+
+       if (!TransactNamedPipe(h, cmds, sizeof(cmds[0])*num_cmds, errbuf, sizeof(errbuf), &numio, NULL)) {
+               printf("TransactNamedPipe failed: %d!\n", GetLastError());
+               return -1;
+       }
+
+       printf("Trans: %d\n", numio);
+       numio = 0;
+       if (!WriteFile(h, buf, sizeof(buf), &numio, NULL)) {
+               printf("Error writing: %d\n", GetLastError());
+               return -1;
+       }
+
+       printf("Write: %d\n", numio);
+       numio = 0;
+
+       if (!ReadFile(h, buf, sizeof(buf), &numio, NULL)) {
+               printf("Error reading: %d\n", GetLastError());
+               return -1;
+       }
+
+       printf("Read: %d\n", numio);
+       numio = 0;
+
+       if (!TransactNamedPipe(h, buf, sizeof(buf), buf, sizeof(buf), &numio, NULL)) {
+               printf("TransactNamedPipe failed: %d!\n", GetLastError());
+               return -1;
+       }
+
+       printf("Trans: %d\n", numio);
+       numio = 0;
+
+       return 0;
+}