winbind: Make domain_name const in wcache_ndr_key().
[Samba/vl.git] / source3 / torture / test_addrchange.c
blobdaf0488aa18a15e3a6f0cd1e8592fd25ac4b37e2
1 /*
2 Unix SMB/CIFS implementation.
3 test for the addrchange functionality
4 Copyright (C) Volker Lendecke 2011
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.
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.
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/>.
20 #include "includes.h"
21 #include "lib/addrchange.h"
22 #include "lib/util/tevent_ntstatus.h"
23 #include "proto.h"
25 extern int torture_numops;
27 bool run_addrchange(int dummy)
29 struct addrchange_context *ctx;
30 struct tevent_context *ev;
31 NTSTATUS status;
32 int i;
34 ev = samba_tevent_context_init(talloc_tos());
35 if (ev == NULL) {
36 d_fprintf(stderr, "tevent_context_init failed\n");
37 return -1;
40 status = addrchange_context_create(talloc_tos(), &ctx);
41 if (!NT_STATUS_IS_OK(status)) {
42 d_fprintf(stderr, "addrchange_context_create failed: %s\n",
43 nt_errstr(status));
44 return false;
47 for (i=0; i<torture_numops; i++) {
48 enum addrchange_type type;
49 struct sockaddr_storage addr;
50 struct tevent_req *req;
51 const char *typestr;
52 char addrstr[INET6_ADDRSTRLEN];
54 req = addrchange_send(talloc_tos(), ev, ctx);
55 if (req == NULL) {
56 d_fprintf(stderr, "addrchange_send failed\n");
57 return -1;
60 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
61 d_fprintf(stderr, "tevent_req_poll_ntstatus failed: "
62 "%s\n", nt_errstr(status));
63 TALLOC_FREE(req);
64 return -1;
67 status = addrchange_recv(req, &type, &addr);
68 TALLOC_FREE(req);
69 if (!NT_STATUS_IS_OK(status)) {
70 d_fprintf(stderr, "addrchange_recv failed: %s\n",
71 nt_errstr(status));
72 return -1;
75 switch(type) {
76 case ADDRCHANGE_ADD:
77 typestr = "add";
78 break;
79 case ADDRCHANGE_DEL:
80 typestr = "del";
81 break;
82 default:
83 typestr = talloc_asprintf(talloc_tos(), "unknown %d",
84 (int)type);
85 break;
88 printf("Got %s %s\n", typestr,
89 print_sockaddr(addrstr, sizeof(addrstr), &addr));
91 TALLOC_FREE(ctx);
92 TALLOC_FREE(ev);
93 return 0;