From 64f0348a3f994334abe64a4d4896109c3c8c9039 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Dec 1997 14:16:07 +0000 Subject: This is it ! The mega-merge of the JRA_NMBD_REWRITE branch back into the main tree. For the cvs logs of all the files starting nmbd_*.c, look in the JRA_NMBD_REWRITE branch. That branch has now been discontinued. Jeremy. (This used to be commit d80b0cb645f81d16734929a0b27a91c6650499bb) --- source3/libsmb/namequery.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'source3/libsmb/namequery.c') diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 15bf58bc55..9915ee92a8 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -189,21 +189,25 @@ BOOL name_status(int fd,char *name,int name_type,BOOL recurse, /**************************************************************************** do a netbios name query to find someones IP + returns an array of IP addresses or NULL if none + *count will be set to the number of addresses returned ****************************************************************************/ -BOOL name_query(int fd,char *name,int name_type, - BOOL bcast,BOOL recurse, - struct in_addr to_ip, struct in_addr *ip,void (*fn)()) +struct in_addr *name_query(int fd,char *name,int name_type, + BOOL bcast,BOOL recurse, + struct in_addr to_ip, int *count, void (*fn)()) { BOOL found=False; - int retries = 3; + int i, retries = 3; int retry_time = bcast?250:2000; struct timeval tval; struct packet_struct p; struct packet_struct *p2; struct nmb_packet *nmb = &p.packet.nmb; static int name_trn_id = 0; + struct in_addr *ip_list = NULL; bzero((char *)&p,sizeof(p)); + (*count) = 0; if (!name_trn_id) name_trn_id = (time(NULL)%(unsigned)0x7FFF) + (getpid()%(unsigned)100); @@ -237,7 +241,7 @@ BOOL name_query(int fd,char *name,int name_type, GetTimeOfDay(&tval); if (!send_packet(&p)) - return(False); + return NULL; retries--; @@ -248,7 +252,7 @@ BOOL name_query(int fd,char *name,int name_type, if (TvalDiff(&tval,&tval2) > retry_time) { if (!retries) break; if (!found && !send_packet(&p)) - return False; + return NULL; GetTimeOfDay(&tval); retries--; } @@ -256,7 +260,7 @@ BOOL name_query(int fd,char *name,int name_type, if ((p2=receive_packet(fd,NMB_PACKET,90))) { struct nmb_packet *nmb2 = &p2->packet.nmb; - debug_nmb_packet(p2); + debug_nmb_packet(p2); if (nmb->header.name_trn_id != nmb2->header.name_trn_id || !nmb2->header.response) { @@ -279,11 +283,17 @@ BOOL name_query(int fd,char *name,int name_type, continue; } - if (ip) { - putip((char *)ip,&nmb2->answers->rdata[2]); - DEBUG(fn?3:2,("Got a positive name query response from %s", - inet_ntoa(p2->ip))); - DEBUG(fn?3:2,(" (%s)\n",inet_ntoa(*ip))); + ip_list = (struct in_addr *)Realloc(ip_list, sizeof(ip_list[0]) * + ((*count)+nmb2->answers->rdlength/6)); + if (ip_list) { + DEBUG(fn?3:2,("Got a positive name query response from %s ( ", + inet_ntoa(p2->ip))); + for (i=0;ianswers->rdlength/6;i++) { + putip((char *)&ip_list[(*count)],&nmb2->answers->rdata[2+i*6]); + DEBUG(fn?3:2,("%s ",inet_ntoa(ip_list[(*count)]))); + (*count)++; + } + DEBUG(fn?3:2,(")\n")); } found=True; retries=0; free_packet(p2); @@ -291,5 +301,5 @@ BOOL name_query(int fd,char *name,int name_type, } } - return(found); + return ip_list; } -- cgit