b101f62960204d11947784582016d6d8485ad135
[samba-svnmirror.git] / source / torture / libnet / libnet_lookup.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2005
6    
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "libnet/libnet.h"
24 #include "libnet/composite.h"
25 #include "libcli/composite/monitor.h"
26 #include "librpc/gen_ndr/ndr_nbt.h"
27
28
29 BOOL torture_lookup(void)
30 {
31         NTSTATUS status;
32         TALLOC_CTX *mem_ctx;
33         struct libnet_Lookup lookup;
34         const char address[16];
35         const char** methods = lp_name_resolve_order();
36
37         mem_ctx = talloc_init("test_lookup");
38
39         lookup.in.hostname = lp_netbios_name();
40         lookup.in.methods  = lp_name_resolve_order();
41         lookup.in.type     = NBT_NAME_CLIENT;
42         lookup.out.address = (const char**)&address;
43
44         status = libnet_Lookup(mem_ctx, &lookup);
45
46         if (!NT_STATUS_IS_OK(status)) {
47                 printf("Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status));
48                 return False;
49         }
50
51         return True;
52 }
53
54
55 BOOL torture_lookup_host(void)
56 {
57         NTSTATUS status;
58         TALLOC_CTX *mem_ctx;
59         struct libnet_Lookup lookup;
60         const char address[16];
61         const char** methods = lp_name_resolve_order();
62
63         mem_ctx = talloc_init("test_lookup_host");
64
65         lookup.in.hostname = lp_netbios_name();
66         lookup.in.methods  = lp_name_resolve_order();
67         lookup.out.address = (const char**)&address;
68
69         status = libnet_LookupHost(mem_ctx, &lookup);
70
71         if (!NT_STATUS_IS_OK(status)) {
72                 printf("Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status));
73                 return False;
74         }
75
76         return True;
77 }
78
79
80 BOOL torture_lookup_pdc(void)
81 {
82         NTSTATUS status;
83         TALLOC_CTX *mem_ctx;
84         struct libnet_Lookup lookup;
85         const char address[16];
86         const char** methods = lp_name_resolve_order();
87
88         mem_ctx = talloc_init("test_lookup_pdc");
89
90         lookup.in.hostname = lp_workgroup();
91         lookup.in.methods  = lp_name_resolve_order();
92         lookup.out.address = (const char**)&address;
93
94         status = libnet_LookupPdc(mem_ctx, &lookup);
95
96         if (!NT_STATUS_IS_OK(status)) {
97                 printf("Couldn't lookup pdc %s: %s\n", lookup.in.hostname, nt_errstr(status));
98                 return False;
99         }
100
101         return True;
102 }