source: branches/samba-3.5.x/testprogs/win32/npecho/npecho_client.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 1.1 KB
Line 
1/*
2 * Simple Named Pipe Client
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 * Published to the public domain
5 */
6
7#include <windows.h>
8#include <stdio.h>
9
10#define ECHODATA "Black Dog"
11
12int main(int argc, char *argv[])
13{
14 HANDLE h;
15 DWORD numread = 0;
16 char *outbuffer = malloc(strlen(ECHODATA));
17
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;
22 }
23
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;
28 }
29
30 if (!WriteFile(h, ECHODATA, strlen(ECHODATA), &numread, NULL)) {
31 printf("Error writing: %d\n", GetLastError());
32 return -1;
33 }
34
35 if (!ReadFile(h, outbuffer, strlen(ECHODATA), &numread, NULL)) {
36 printf("Error reading: %d\n", GetLastError());
37 return -1;
38 }
39
40 printf("Read: %s\n", outbuffer);
41
42 if (!TransactNamedPipe(h, ECHODATA, strlen(ECHODATA), outbuffer, strlen(ECHODATA), &numread, NULL)) {
43 printf("TransactNamedPipe failed: %d!\n", GetLastError());
44 return -1;
45 }
46
47 printf("Result: %s\n", outbuffer);
48
49 return 0;
50}
Note: See TracBrowser for help on using the repository browser.