r9794: r11627@blu: tridge | 2005-08-30 22:55:27 +1000
[ira/wip.git] / source / nbt_server / nbt_server.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    NBT server structures
5
6    Copyright (C) Andrew Tridgell        2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "libcli/nbt/libnbt.h"
24 #include "libcli/dgram/libdgram.h"
25 #include "librpc/gen_ndr/ndr_irpc.h"
26 #include "lib/messaging/irpc.h"
27
28 /* 
29    a list of our registered names on each interface
30 */
31 struct nbtd_iface_name {
32         struct nbtd_iface_name *next, *prev;
33         struct nbtd_interface *iface;
34         struct nbt_name name;
35         uint16_t nb_flags;
36         struct timeval registration_time;
37         uint32_t ttl;
38
39         /* if registered with a wins server, then this lists the server being
40            used */
41         char *wins_server;
42 };
43
44
45 /* a list of network interfaces we are listening on */
46 struct nbtd_interface {
47         struct nbtd_interface *next, *prev;
48         struct nbtd_server *nbtsrv;
49         const char *ip_address;
50         const char *bcast_address;
51         const char *netmask;
52         struct nbt_name_socket *nbtsock;
53         struct nbt_dgram_socket *dgmsock;
54         struct nbtd_iface_name *names;
55 };
56
57
58 /*
59   top level context structure for the nbt server
60 */
61 struct nbtd_server {
62         struct task_server *task;
63
64         /* the list of local network interfaces */
65         struct nbtd_interface *interfaces;
66
67         /* broadcast interface used for receiving packets only */
68         struct nbtd_interface *bcast_interface;
69
70         /* wins client interface - used for registering and refreshing
71            our names with a WINS server */
72         struct nbtd_interface *wins_interface;
73
74         struct wins_server *winssrv;
75
76         struct nbtd_statistics stats;
77 };
78
79
80
81 /* check a condition on an incoming packet */
82 #define NBTD_ASSERT_PACKET(packet, src_address, test) do { \
83         if (!(test)) { \
84                 nbtd_bad_packet(packet, src_address, #test); \
85                 return; \
86         } \
87 } while (0)
88
89 /* this copes with the nasty hack that is the type 0x1c name */
90 #define IS_GROUP_NAME(name, nb_flags) \
91         ((name)->type != NBT_NAME_LOGON && (nb_flags & NBT_NM_GROUP))