typo
[Samba.git] / source3 / rpcclient / cmd_echo.c
blob79ba744a55a7bba6702885213b0f5b41c2f318da
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Tim Potter 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "rpcclient.h"
25 static NTSTATUS cmd_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx,
26 int argc, const char **argv)
28 uint32 request = 1, response;
29 NTSTATUS result;
31 if (argc > 2) {
32 printf("Usage: %s [num]\n", argv[0]);
33 return NT_STATUS_OK;
36 if (argc == 2)
37 request = atoi(argv[1]);
39 result = cli_echo_add_one(cli, mem_ctx, request, &response);
41 if (!NT_STATUS_IS_OK(result))
42 goto done;
44 printf("%d + 1 = %d\n", request, response);
46 done:
47 return result;
50 static NTSTATUS cmd_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
51 int argc, const char **argv)
53 uint32 size, i;
54 NTSTATUS result;
55 char *in_data = NULL, *out_data = NULL;
57 if (argc != 2) {
58 printf("Usage: %s num\n", argv[0]);
59 return NT_STATUS_OK;
62 size = atoi(argv[1]);
63 in_data = malloc(size);
65 for (i = 0; i < size; i++)
66 in_data[i] = i & 0xff;
68 result = cli_echo_data(cli, mem_ctx, size, in_data, &out_data);
70 if (!NT_STATUS_IS_OK(result))
71 goto done;
73 for (i = 0; i < size; i++) {
74 if (in_data[i] != out_data[i]) {
75 printf("mismatch at offset %d, %d != %d\n",
76 i, in_data[i], out_data[i]);
80 done:
81 SAFE_FREE(in_data);
83 return result;
86 static NTSTATUS cmd_echo_source_data(struct cli_state *cli,
87 TALLOC_CTX *mem_ctx, int argc,
88 const char **argv)
90 uint32 size, i;
91 NTSTATUS result;
92 char *out_data = NULL;
94 if (argc != 2) {
95 printf("Usage: %s num\n", argv[0]);
96 return NT_STATUS_OK;
99 size = atoi(argv[1]);
101 result = cli_echo_source_data(cli, mem_ctx, size, &out_data);
103 if (!NT_STATUS_IS_OK(result))
104 goto done;
106 for (i = 0; i < size; i++) {
107 if (out_data && out_data[i] != (i & 0xff)) {
108 printf("mismatch at offset %d, %d != %d\n",
109 i, out_data[i], i & 0xff);
113 done:
114 return result;
117 static NTSTATUS cmd_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
118 int argc, const char **argv)
120 uint32 size, i;
121 NTSTATUS result;
122 char *in_data = NULL;
124 if (argc != 2) {
125 printf("Usage: %s num\n", argv[0]);
126 return NT_STATUS_OK;
129 size = atoi(argv[1]);
130 in_data = malloc(size);
132 for (i = 0; i < size; i++)
133 in_data[i] = i & 0xff;
135 result = cli_echo_sink_data(cli, mem_ctx, size, in_data);
137 if (!NT_STATUS_IS_OK(result))
138 goto done;
140 done:
141 SAFE_FREE(in_data);
143 return result;
146 /* List of commands exported by this module */
148 struct cmd_set echo_commands[] = {
150 { "ECHO" },
152 { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, PI_ECHO, "Add one to a number", "" },
153 { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, PI_ECHO, "Echo data", "" },
154 { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, PI_ECHO, "Sink data", "" },
155 { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_ECHO, "Source data", "" },
156 { NULL }