1290b53dc64ac01775a9dc336158087a580603cd
[kai/samba.git] / source4 / torture / rpc / countcalls.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    count number of calls on an interface
5
6    Copyright (C) Andrew Tridgell 2003
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "torture/torture.h"
25 #include "librpc/rpc/dcerpc.h"
26 #include "librpc/rpc/dcerpc_table.h"
27 #include "torture/rpc/rpc.h"
28
29
30 BOOL torture_rpc_countcalls(void)
31 {
32         const struct dcerpc_interface_table *iface;
33         NTSTATUS status;
34         struct dcerpc_pipe *p;
35         int i;
36         const char *iface_name;
37         DATA_BLOB stub_in, stub_out;
38         
39         iface_name = lp_parm_string(-1, "countcalls", "interface");
40         if (iface_name == NULL) {
41                 printf("You must specify an interface name with countcalls:interface\n");
42                 return False;
43         }
44
45         iface = idl_iface_by_name(iface_name);
46         if (!iface) {
47                 printf("Unknown interface '%s'\n", iface_name);
48                 return False;
49         }
50
51         status = torture_rpc_connection(NULL, &p, iface);
52         if (!NT_STATUS_IS_OK(status)) {
53                 printf("Failed to open '%s' - %s\n", iface->name, nt_errstr(status));
54                 return False;
55         }
56
57         stub_in = data_blob_talloc(p, NULL, 0);
58
59         printf("\nScanning pipe '%s'\n", iface->name);
60
61         for (i=0;i<5000;i++) {
62                 status = dcerpc_request(p, NULL, i, False, p, &stub_in, &stub_out);
63                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT) &&
64                     p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) break;
65                 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
66                         break;
67                 }
68         }
69         
70         if (i==5000) {
71                 talloc_free(p);
72                 printf("no limit on calls!?\n");
73                 return False;
74         }
75
76         printf("Found %d calls\n", i);
77
78         talloc_free(p);
79
80         return True;
81 }