diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
commit | 8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch) | |
tree | 4099e8021376c7d8c05bdf8503093d80e9c7bad0 /testprogs/win32/npecho/npecho_client.c | |
parent | Initial commit. (diff) | |
download | samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip |
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testprogs/win32/npecho/npecho_client.c')
-rwxr-xr-x | testprogs/win32/npecho/npecho_client.c | 50 |
1 files changed, 50 insertions, 0 deletions
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; +} |