This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[kai/samba-autobuild/.git] / source / web / diagnose.c
1 /* 
2    Unix SMB/CIFS implementation.
3    diagnosis tools for web admin
4    Copyright (C) Andrew Tridgell 1998
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "smb.h"
23
24
25 /* check to see if nmbd is running on localhost by looking for a __SAMBA__
26    response */
27 BOOL nmbd_running(void)
28 {
29         extern struct in_addr loopback_ip;
30         int fd, count;
31         struct in_addr *ip_list;
32
33         if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
34                                  interpret_addr("127.0.0.1"), True)) != -1) {
35                 if ((ip_list = name_query(fd, "__SAMBA__", 0, 
36                                           True, True, loopback_ip,
37                                           &count)) != NULL) {
38                         SAFE_FREE(ip_list);
39                         close(fd);
40                         return True;
41                 }
42                 close (fd);
43         }
44
45         return False;
46 }
47
48
49 /* check to see if smbd is running on localhost by trying to open a connection
50    then closing it */
51 BOOL smbd_running(void)
52 {
53         static struct cli_state cli;
54         extern struct in_addr loopback_ip;
55
56         if (!cli_initialise(&cli))
57                 return False;
58
59         if (!cli_connect(&cli, "localhost", &loopback_ip)) {
60                 cli_shutdown(&cli);
61                 return False;
62         }
63
64         cli_shutdown(&cli);
65         return True;
66 }