wintest: set nameserver on a more general place
[Samba/gebeck_regimport.git] / testprogs / win32 / npecho / npecho_server2.c
blob281fc458332d41ee093b7765df9c7510b5e6b512
1 /*
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
6 */
8 #include <windows.h>
9 #include <stdio.h>
11 #define ECHODATA "Black Dog"
13 int main(int argc, char *argv[])
15 HANDLE h;
16 DWORD numread = 0;
17 char *outbuffer = malloc(sizeof(ECHODATA));
18 BOOL msgmode = FALSE;
19 DWORD type = 0;
21 if (argc == 1) {
22 goto usage;
23 } else if (argc >= 3) {
24 if (strcmp(argv[2], "byte") == 0) {
25 msgmode = FALSE;
26 } else if (strcmp(argv[2], "message") == 0) {
27 msgmode = TRUE;
28 } else {
29 goto usage;
33 if (msgmode == TRUE) {
34 printf("using message mode\n");
35 type = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT;
36 } else {
37 printf("using byte mode\n");
38 type = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT;
41 h = CreateNamedPipe(argv[1],
42 PIPE_ACCESS_DUPLEX,
43 type,
44 PIPE_UNLIMITED_INSTANCES,
45 1024,
46 1024,
48 NULL);
49 if (h == INVALID_HANDLE_VALUE) {
50 printf("Error opening: %d\n", GetLastError());
51 return -1;
54 ConnectNamedPipe(h, NULL);
56 if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
57 printf("Error writing: %d\n", GetLastError());
58 return -1;
61 if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) {
62 printf("Error writing: %d\n", GetLastError());
63 return -1;
66 FlushFileBuffers(h);
67 DisconnectNamedPipe(h);
68 CloseHandle(h);
70 return 0;
71 usage:
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");
75 return -1;