first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[samba.git] / source3 / web / diagnose.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    diagnosis tools for web admin
5    Copyright (C) Andrew Tridgell 1998
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 "smb.h"
24
25
26 /* check to see if nmbd is running on localhost by looking for a __SAMBA__
27    response */
28 BOOL nmbd_running(void)
29 {
30         extern struct in_addr loopback_ip;
31         int fd, count;
32         struct in_addr *ip_list;
33
34         if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
35                                  interpret_addr("127.0.0.1"), True)) != -1) {
36                 if ((ip_list = name_query(fd, "__SAMBA__", 0, 
37                                           True, True, loopback_ip,
38                                           &count,0)) != NULL) {
39                         free(ip_list);
40                         close(fd);
41                         return True;
42                 }
43                 close (fd);
44         }
45
46         return False;
47 }
48
49
50 /* check to see if smbd is running on localhost by trying to open a connection
51    then closing it */
52 BOOL smbd_running(void)
53 {
54         static struct cli_state cli;
55         extern struct in_addr loopback_ip;
56
57         if (!cli_initialise(&cli))
58                 return False;
59
60         if (!cli_connect(&cli, "localhost", &loopback_ip)) {
61                 cli_shutdown(&cli);
62                 return False;
63         }
64
65         cli_shutdown(&cli);
66         return True;
67 }