summaryrefslogtreecommitdiffstats
path: root/testprogs/win32/npecho
diff options
context:
space:
mode:
Diffstat (limited to 'testprogs/win32/npecho')
-rwxr-xr-xtestprogs/win32/npecho/GNUmakefile24
-rwxr-xr-xtestprogs/win32/npecho/NMakefile26
-rwxr-xr-xtestprogs/win32/npecho/npecho_client.c50
-rwxr-xr-xtestprogs/win32/npecho/npecho_client2.c117
-rwxr-xr-xtestprogs/win32/npecho/npecho_server2.c76
5 files changed, 293 insertions, 0 deletions
diff --git a/testprogs/win32/npecho/GNUmakefile b/testprogs/win32/npecho/GNUmakefile
new file mode 100755
index 0000000..5b4f976
--- /dev/null
+++ b/testprogs/win32/npecho/GNUmakefile
@@ -0,0 +1,24 @@
+INCLUDES=-I.
+CFLAGS=$(INCLUDES)
+
+NPECHO = npecho_client.exe
+#npecho_server.exe
+
+NPECHO2 = npecho_client2.exe npecho_server2.exe
+
+all: $(NPECHO) $(NPECHO2)
+
+MINGW_CC = i586-mingw32msvc-cc
+CC = $(MINGW_CC)
+
+.SUFFIXES: .c .obj .exe
+
+.c.obj:
+ $(CC) $(CFLAGS) -c $< -o $@
+
+.obj.exe:
+ $(CC) $(CFLAGS) -o $@ $< $(LIBS)
+
+clean:
+ rm -f *~ *.obj *.exe
+
diff --git a/testprogs/win32/npecho/NMakefile b/testprogs/win32/npecho/NMakefile
new file mode 100755
index 0000000..a0e61d7
--- /dev/null
+++ b/testprogs/win32/npecho/NMakefile
@@ -0,0 +1,26 @@
+#
+# use nmake /f NMakefile [<target>]
+#
+INCLUDES=-I
+CFLAGS=$(INCLUDES) -Zi -nologo
+
+NPECHO = npecho_client.exe
+# missing npecho_server.exe
+NPECHO2 = npecho_client2.exe npecho_server2.exe
+
+all: $(NPECHO) $(NPECHO2)
+
+clean:
+ del *~ *.obj *.exe
+
+npecho_client.exe: npecho_client.obj
+ $(CC) $(CFLAGS) -o npecho_client.exe npecho_client.obj $(LIBS)
+
+npecho_server.exe: npecho_server.obj
+ $(CC) $(CFLAGS) -o npecho_server.exe npecho_server.obj $(LIBS)
+
+npecho_client2.exe: npecho_client2.obj
+ $(CC) $(CFLAGS) -o npecho_client2.exe npecho_client2.obj $(LIBS)
+
+npecho_server2.exe: npecho_server2.obj
+ $(CC) $(CFLAGS) -o npecho_server2.exe npecho_server2.obj $(LIBS)
diff --git a/testprogs/win32/npecho/npecho_client.c b/testprogs/win32/npecho/npecho_client.c
new file mode 100755
index 0000000..97d31c4
--- /dev/null
+++ b/testprogs/win32/npecho/npecho_client.c
@@ -0,0 +1,50 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define ECHODATA "Black Dog"
+
+int main(int argc, char *argv[])
+{
+ HANDLE h;
+ DWORD numread = 0;
+ char *outbuffer = malloc(strlen(ECHODATA));
+
+ 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 (!WriteFile(h, ECHODATA, strlen(ECHODATA), &numread, NULL)) {
+ printf("Error writing: %d\n", GetLastError());
+ return -1;
+ }
+
+ if (!ReadFile(h, outbuffer, strlen(ECHODATA), &numread, NULL)) {
+ printf("Error reading: %d\n", GetLastError());
+ return -1;
+ }
+
+ printf("Read: %s\n", outbuffer);
+
+ if (!TransactNamedPipe(h, ECHODATA, strlen(ECHODATA), outbuffer, strlen(ECHODATA), &numread, NULL)) {
+ printf("TransactNamedPipe failed: %d!\n", GetLastError());
+ return -1;
+ }
+
+ printf("Result: %s\n", outbuffer);
+
+ return 0;
+}
diff --git a/testprogs/win32/npecho/npecho_client2.c b/testprogs/win32/npecho/npecho_client2.c
new file mode 100755
index 0000000..ebf4f9a
--- /dev/null
+++ b/testprogs/win32/npecho/npecho_client2.c
@@ -0,0 +1,117 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * (C) 2009 Stefan Metzmacher <metze@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define ECHODATA "Black Dog"
+
+int main(int argc, char *argv[])
+{
+ HANDLE h;
+ DWORD numread = 0;
+ char *outbuffer = malloc(sizeof(ECHODATA)*2);
+ BOOL small_reads = FALSE;
+ DWORD state = 0;
+ DWORD flags = 0;
+
+ if (argc == 1) {
+ goto usage;
+ } else if (argc >= 3) {
+ if (strcmp(argv[2], "large") == 0) {
+ small_reads = FALSE;
+ } else if (strcmp(argv[2], "small") == 0) {
+ small_reads = TRUE;
+ } else {
+ goto usage;
+ }
+ }
+
+ 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;
+ }
+
+ GetNamedPipeHandleState(h, &state, NULL, NULL, NULL, NULL, 0);
+
+ if (state & PIPE_READMODE_MESSAGE) {
+ printf("message read mode\n");
+ } else {
+ printf("byte read mode\n");
+ }
+
+ Sleep(5000);
+
+ if (small_reads) {
+ DWORD ofs, size, nread;
+ const char *more = "";
+ printf("small reads\n");
+ numread = 0;
+ ofs = 0;
+ size = sizeof(ECHODATA)/2;
+ if (ReadFile(h, outbuffer+ofs, size, &nread, NULL)) {
+ if (state & PIPE_READMODE_MESSAGE) {
+ printf("Error message mode small read succeeded\n");
+ return -1;
+ }
+ } else if (GetLastError() == ERROR_MORE_DATA) {
+ if (!(state & PIPE_READMODE_MESSAGE)) {
+ printf("Error byte mode small read returned ERROR_MORE_DATA\n");
+ return -1;
+ }
+ more = " more data";
+ } else {
+ printf("Error reading: %d\n", GetLastError());
+ return -1;
+ }
+ printf("Small Read: %d%s\n", nread, more);
+ numread += nread;
+ ofs = size;
+ size = sizeof(ECHODATA) - ofs;
+ if (!ReadFile(h, outbuffer+ofs, size, &nread, NULL)) {
+ printf("Error reading: %d\n", GetLastError());
+ return -1;
+ }
+ printf("Small Read: %d\n", nread);
+ numread += nread;
+ } else {
+ printf("large read\n");
+ if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
+ printf("Error reading: %d\n", GetLastError());
+ return -1;
+ }
+ }
+ printf("Read: %s %d\n", outbuffer, numread);
+ if (state & PIPE_READMODE_MESSAGE) {
+ if (numread != sizeof(ECHODATA)) {
+ printf("message mode returned %d bytes should be %s\n",
+ numread, sizeof(ECHODATA));
+ return -1;
+ }
+ } else {
+ if (numread != (sizeof(ECHODATA)*2)) {
+ printf("message mode returned %d bytes should be %s\n",
+ numread, (sizeof(ECHODATA)*2));
+ return -1;
+ }
+ }
+
+ if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
+ printf("Error reading: %d\n", GetLastError());
+ return -1;
+ }
+
+ printf("Read: %s %d\n", outbuffer, numread);
+
+ return 0;
+usage:
+ printf("Usage: %s pipename [read]\n", argv[0]);
+ printf(" Where pipename is something like \\\\servername\\NPECHO\n");
+ printf(" Where read is something 'large' or 'small'\n");
+ return -1;
+}
diff --git a/testprogs/win32/npecho/npecho_server2.c b/testprogs/win32/npecho/npecho_server2.c
new file mode 100755
index 0000000..281fc45
--- /dev/null
+++ b/testprogs/win32/npecho/npecho_server2.c
@@ -0,0 +1,76 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * (C) 2009 Stefan Metzmacher <metze@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define ECHODATA "Black Dog"
+
+int main(int argc, char *argv[])
+{
+ HANDLE h;
+ DWORD numread = 0;
+ char *outbuffer = malloc(sizeof(ECHODATA));
+ BOOL msgmode = FALSE;
+ DWORD type = 0;
+
+ if (argc == 1) {
+ goto usage;
+ } else if (argc >= 3) {
+ if (strcmp(argv[2], "byte") == 0) {
+ msgmode = FALSE;
+ } else if (strcmp(argv[2], "message") == 0) {
+ msgmode = TRUE;
+ } else {
+ goto usage;
+ }
+ }
+
+ if (msgmode == TRUE) {
+ printf("using message mode\n");
+ type = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT;
+ } else {
+ printf("using byte mode\n");
+ type = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT;
+ }
+
+ h = CreateNamedPipe(argv[1],
+ PIPE_ACCESS_DUPLEX,
+ type,
+ PIPE_UNLIMITED_INSTANCES,
+ 1024,
+ 1024,
+ 0,
+ NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ printf("Error opening: %d\n", GetLastError());
+ return -1;
+ }
+
+ ConnectNamedPipe(h, NULL);
+
+ if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
+ printf("Error writing: %d\n", GetLastError());
+ return -1;
+ }
+
+ if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
+ printf("Error writing: %d\n", GetLastError());
+ return -1;
+ }
+
+ FlushFileBuffers(h);
+ DisconnectNamedPipe(h);
+ CloseHandle(h);
+
+ return 0;
+usage:
+ printf("Usage: %s pipename [mode]\n", argv[0]);
+ printf(" Where pipename is something like \\\\servername\\PIPE\\NPECHO\n");
+ printf(" Where mode is 'byte' or 'message'\n");
+ return -1;
+}