summaryrefslogtreecommitdiff
path: root/source3/libsmb/namequery.c
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-12-04 23:40:21 +0000
committerLuke Leighton <lkcl@samba.org>1999-12-04 23:40:21 +0000
commitddda7722a673cefc89a55133f99c07dd153b1f19 (patch)
tree6b2148dfa7539cb48e45f76103d2fb41d848a598 /source3/libsmb/namequery.c
parent97913d82f56388eee7d8fa8c204a1fa8c9754b88 (diff)
downloadsamba-ddda7722a673cefc89a55133f99c07dd153b1f19.tar.gz
samba-ddda7722a673cefc89a55133f99c07dd153b1f19.tar.bz2
samba-ddda7722a673cefc89a55133f99c07dd153b1f19.zip
argh! how horrible! spent ages working out why packets weren't being
received properly when a UDP "retry" occurs. it's because reads and writes must be interleaved / matched. scenario: nmblookup connects to agent, sends request. agent receives request, broadcasts it on 137. agent RECEIVES 137 broadcast, sends it to nmblookup agent receives RESPONSE to 137 broadcast, sends it to nmblookup. if reads are not equally interspersed with writes, then second send will fail. if you think this is odd behaviour and that the agent should be filtering its own UDP traffic, think again. agent will be, potentially, redirecting nmbd traffic (including WINS server) not just client programs. (This used to be commit 43e158c4261e51678d6e7f77ceb4a1c7281a2525)
Diffstat (limited to 'source3/libsmb/namequery.c')
-rw-r--r--source3/libsmb/namequery.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 0d9cc54f21..406a5721c9 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -102,6 +102,7 @@ BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
struct packet_struct *p2;
struct nmb_packet *nmb = &p.packet.nmb;
int packet_type = NMB_PACKET;
+ BOOL first_time = True;
if (fd == -1)
{
@@ -147,27 +148,19 @@ BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
GetTimeOfDay(&tval);
- if (!send_packet(&p))
- {
- if (packet_type == NMB_SOCK_PACKET) close(fd);
- return(False);
- }
-
- retries--;
-
while (1)
{
struct timeval tval2;
GetTimeOfDay(&tval2);
- if (TvalDiff(&tval,&tval2) > retry_time) {
- if (!retries) break;
+ if (first_time || TvalDiff(&tval,&tval2) > retry_time)
+ {
+ first_time = False;
if (!found && !send_packet(&p))
{
if (packet_type == NMB_SOCK_PACKET) close(fd);
return False;
}
GetTimeOfDay(&tval);
- retries--;
}
if ((p2=receive_packet(fd,packet_type,90)))
@@ -196,6 +189,8 @@ BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
continue;
}
+ retries--;
+
_interpret_node_status(&nmb2->answers->rdata[0], master,rname);
free_packet(p2);
if (packet_type == NMB_SOCK_PACKET) close(fd);
@@ -221,17 +216,18 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
{
BOOL found=False;
int i, retries = 3;
- int retry_time = bcast?250:2000;
+ int retry_time = bcast?2000:2000;
struct timeval tval;
struct packet_struct p;
struct packet_struct *p2;
struct nmb_packet *nmb = &p.packet.nmb;
struct in_addr *ip_list = NULL;
BOOL packet_type = NMB_PACKET;
+ BOOL first_send = True;
if (fd == -1)
{
- retries = 0;
+ retries = 1;
packet_type = NMB_SOCK_PACKET;
fd = get_nmb_sock();
@@ -273,15 +269,16 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
p.timestamp = time(NULL);
p.packet_type = packet_type;
- ZERO_STRUCT(tval);
+ GetTimeOfDay(&tval);
while (retries >= 0)
{
struct timeval tval2;
GetTimeOfDay(&tval2);
- if (TvalDiff(&tval,&tval2) > retry_time)
+ if (first_send ) /* || TvalDiff(&tval,&tval2) > retry_time) */
{
+ first_send = False;
if (!found && !send_packet(&p))
{
if (packet_type == NMB_SOCK_PACKET) close(fd);
@@ -308,6 +305,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
fn(p2);
else
free_packet(p2);
+
continue;
}