2 * Simple Named Pipe Client
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
4 * (C) 2009 Stefan Metzmacher <metze@samba.org>
5 * Published to the public domain
11 #define ECHODATA "Black Dog"
13 int main(int argc, char *argv[])
17 char *outbuffer = malloc(sizeof(ECHODATA));
23 } else if (argc >= 3) {
24 if (strcmp(argv[2], "byte") == 0) {
26 } else if (strcmp(argv[2], "message") == 0) {
33 if (msgmode == TRUE) {
34 printf("using message mode\n");
35 type = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT;
37 printf("using byte mode\n");
38 type = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT;
41 h = CreateNamedPipe(argv[1],
44 PIPE_UNLIMITED_INSTANCES,
49 if (h == INVALID_HANDLE_VALUE) {
50 printf("Error opening: %d\n", GetLastError());
54 ConnectNamedPipe(h, NULL);
56 if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
57 printf("Error writing: %d\n", GetLastError());
61 if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
62 printf("Error writing: %d\n", GetLastError());
67 DisconnectNamedPipe(h);
72 printf("Usage: %s pipename [mode]\n", argv[0]);
73 printf(" Where pipename is something like \\\\servername\\PIPE\\NPECHO\n");
74 printf(" Where mode is 'byte' or 'message'\n");