Line data Source code
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 "lib/util/tevent_ntstatus.h" 23 : #include "proto.h" 24 : 25 : extern int torture_numops; 26 : 27 0 : bool run_addrchange(int dummy) 28 : { 29 0 : struct addrchange_context *ctx; 30 0 : struct tevent_context *ev; 31 0 : NTSTATUS status; 32 0 : int i; 33 : 34 0 : ev = samba_tevent_context_init(talloc_tos()); 35 0 : if (ev == NULL) { 36 0 : d_fprintf(stderr, "tevent_context_init failed\n"); 37 0 : return false; 38 : } 39 : 40 0 : status = addrchange_context_create(talloc_tos(), &ctx); 41 0 : if (!NT_STATUS_IS_OK(status)) { 42 0 : d_fprintf(stderr, "addrchange_context_create failed: %s\n", 43 : nt_errstr(status)); 44 0 : return false; 45 : } 46 : 47 0 : for (i=0; i<torture_numops; i++) { 48 0 : enum addrchange_type type; 49 0 : struct sockaddr_storage addr; 50 0 : struct tevent_req *req; 51 0 : const char *typestr; 52 0 : char addrstr[INET6_ADDRSTRLEN]; 53 : 54 0 : req = addrchange_send(talloc_tos(), ev, ctx); 55 0 : if (req == NULL) { 56 0 : d_fprintf(stderr, "addrchange_send failed\n"); 57 0 : return false; 58 : } 59 : 60 0 : if (!tevent_req_poll_ntstatus(req, ev, &status)) { 61 0 : d_fprintf(stderr, "tevent_req_poll_ntstatus failed: " 62 : "%s\n", nt_errstr(status)); 63 0 : TALLOC_FREE(req); 64 0 : return false; 65 : } 66 : 67 0 : status = addrchange_recv(req, &type, &addr, NULL); 68 0 : TALLOC_FREE(req); 69 0 : if (!NT_STATUS_IS_OK(status)) { 70 0 : d_fprintf(stderr, "addrchange_recv failed: %s\n", 71 : nt_errstr(status)); 72 0 : return false; 73 : } 74 : 75 0 : switch(type) { 76 0 : case ADDRCHANGE_ADD: 77 0 : typestr = "add"; 78 0 : break; 79 0 : case ADDRCHANGE_DEL: 80 0 : typestr = "del"; 81 0 : break; 82 0 : default: 83 0 : typestr = talloc_asprintf(talloc_tos(), "unknown %d", 84 : (int)type); 85 0 : break; 86 : } 87 : 88 0 : printf("Got %s %s\n", typestr, 89 : print_sockaddr(addrstr, sizeof(addrstr), &addr)); 90 : } 91 0 : TALLOC_FREE(ctx); 92 0 : TALLOC_FREE(ev); 93 0 : return true; 94 : }