updating documentation to reflect code a little bit.
[Samba.git] / source / namedbresp.c
blobd89bfe8ae843bbd042faf8dffdaf8ee895c9a87b
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios library routines
5 Copyright (C) Andrew Tridgell 1994-1996
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.
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.
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.
21 Module name: namedbresp.c
25 #include "includes.h"
27 extern int ClientNMB;
28 extern int ClientDGRAM;
30 extern struct subnet_record *subnetlist;
32 extern int DEBUGLEVEL;
34 extern pstring scope;
35 extern pstring myname;
36 extern struct in_addr ipzero;
37 extern struct in_addr ipgrp;
39 int num_response_packets = 0;
41 /***************************************************************************
42 add an expected response record into the list
43 **************************************************************************/
44 void add_response_record(struct subnet_record *d,
45 struct response_record *n)
47 struct response_record *n2;
49 if (!d) return;
51 num_response_packets++; /* count of total number of packets still around */
53 DEBUG(4,("adding response record id:%d num_records:%d\n",
54 n->response_id, num_response_packets));
56 if (!d->responselist)
58 d->responselist = n;
59 n->prev = NULL;
60 n->next = NULL;
61 return;
64 for (n2 = d->responselist; n2->next; n2 = n2->next) ;
66 n2->next = n;
67 n->next = NULL;
68 n->prev = n2;
72 /***************************************************************************
73 remove an expected response record from the list
74 **************************************************************************/
75 void remove_response_record(struct subnet_record *d,
76 struct response_record *n)
78 if (!d) return;
80 if (n->prev) n->prev->next = n->next;
81 if (n->next) n->next->prev = n->prev;
83 if (d->responselist == n) d->responselist = n->next;
85 free(n);
87 num_response_packets--; /* count of total number of packets still around */
91 /****************************************************************************
92 create a name query response record
93 **************************************************************************/
94 struct response_record *make_response_queue_record(enum state_type state,
95 int id,uint16 fd,
96 int quest_type, char *name,int type, int nb_flags, time_t ttl,
97 int server_type, char *my_name, char *my_comment,
98 BOOL bcast,BOOL recurse,
99 struct in_addr send_ip, struct in_addr reply_to_ip)
101 struct response_record *n;
103 if (!name || !name[0]) return NULL;
105 if (!(n = (struct response_record *)malloc(sizeof(*n))))
106 return(NULL);
108 n->response_id = id;
109 n->state = state;
110 n->fd = fd;
111 n->quest_type = quest_type;
112 make_nmb_name(&n->name, name, type, scope);
113 n->nb_flags = nb_flags;
114 n->ttl = ttl;
115 n->server_type = server_type;
116 n->bcast = bcast;
117 n->recurse = recurse;
118 n->send_ip = send_ip;
119 n->reply_to_ip = reply_to_ip;
120 StrnCpy(my_name , n->my_name , sizeof(n->my_name )-1);
121 StrnCpy(my_comment, n->my_comment, sizeof(n->my_comment)-1);
123 n->repeat_interval = 1; /* XXXX should be in ms */
124 n->repeat_count = 3; /* 3 retries */
125 n->repeat_time = time(NULL) + n->repeat_interval; /* initial retry time */
127 n->num_msgs = 0;
129 return n;
133 /****************************************************************************
134 find a response in a subnet's name query response list.
135 **************************************************************************/
136 struct response_record *find_response_record(struct subnet_record **d,
137 uint16 id)
139 struct response_record *n;
141 if (!d) return NULL;
143 for ((*d) = subnetlist; (*d); (*d) = (*d)->next)
145 for (n = (*d)->responselist; n; n = n->next)
147 if (n->response_id == id) {
148 DEBUG(4, ("found response record on %s: %d\n",
149 inet_ntoa((*d)->bcast_ip), id));
150 return n;
155 *d = NULL;
157 return NULL;