1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | test for the addrchange functionality
|
---|
4 | Copyright (C) Volker Lendecke 2011
|
---|
5 |
|
---|
6 | This program is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 3 of the License, or
|
---|
9 | (at your option) any later version.
|
---|
10 |
|
---|
11 | This program is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "lib/addrchange.h"
|
---|
22 | #include "proto.h"
|
---|
23 |
|
---|
24 | extern int torture_numops;
|
---|
25 |
|
---|
26 | bool run_addrchange(int dummy)
|
---|
27 | {
|
---|
28 | struct addrchange_context *ctx;
|
---|
29 | struct tevent_context *ev;
|
---|
30 | NTSTATUS status;
|
---|
31 | int i;
|
---|
32 |
|
---|
33 | ev = tevent_context_init(talloc_tos());
|
---|
34 | if (ev == NULL) {
|
---|
35 | d_fprintf(stderr, "tevent_context_init failed\n");
|
---|
36 | return -1;
|
---|
37 | }
|
---|
38 |
|
---|
39 | status = addrchange_context_create(talloc_tos(), &ctx);
|
---|
40 | if (!NT_STATUS_IS_OK(status)) {
|
---|
41 | d_fprintf(stderr, "addrchange_context_create failed: %s\n",
|
---|
42 | nt_errstr(status));
|
---|
43 | return false;
|
---|
44 | }
|
---|
45 |
|
---|
46 | for (i=0; i<torture_numops; i++) {
|
---|
47 | enum addrchange_type type;
|
---|
48 | struct sockaddr_storage addr;
|
---|
49 | struct tevent_req *req;
|
---|
50 | const char *typestr;
|
---|
51 | char addrstr[INET6_ADDRSTRLEN];
|
---|
52 |
|
---|
53 | req = addrchange_send(talloc_tos(), ev, ctx);
|
---|
54 | if (req == NULL) {
|
---|
55 | d_fprintf(stderr, "addrchange_send failed\n");
|
---|
56 | return -1;
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (!tevent_req_poll_ntstatus(req, ev, &status)) {
|
---|
60 | d_fprintf(stderr, "tevent_req_poll_ntstatus failed: "
|
---|
61 | "%s\n", nt_errstr(status));
|
---|
62 | TALLOC_FREE(req);
|
---|
63 | return -1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | status = addrchange_recv(req, &type, &addr);
|
---|
67 | TALLOC_FREE(req);
|
---|
68 | if (!NT_STATUS_IS_OK(status)) {
|
---|
69 | d_fprintf(stderr, "addrchange_recv failed: %s\n",
|
---|
70 | nt_errstr(status));
|
---|
71 | return -1;
|
---|
72 | }
|
---|
73 |
|
---|
74 | switch(type) {
|
---|
75 | case ADDRCHANGE_ADD:
|
---|
76 | typestr = "add";
|
---|
77 | break;
|
---|
78 | case ADDRCHANGE_DEL:
|
---|
79 | typestr = "del";
|
---|
80 | break;
|
---|
81 | default:
|
---|
82 | typestr = talloc_asprintf(talloc_tos(), "unknown %d",
|
---|
83 | (int)type);
|
---|
84 | break;
|
---|
85 | }
|
---|
86 |
|
---|
87 | printf("Got %s %s\n", typestr,
|
---|
88 | print_sockaddr(addrstr, sizeof(addrstr), &addr));
|
---|
89 | }
|
---|
90 | TALLOC_FREE(ctx);
|
---|
91 | TALLOC_FREE(ev);
|
---|
92 | return 0;
|
---|
93 | }
|
---|