summaryrefslogtreecommitdiff
path: root/source/libsmb/namequery.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/libsmb/namequery.c')
-rw-r--r--source/libsmb/namequery.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/source/libsmb/namequery.c b/source/libsmb/namequery.c
index 15bf58bc559..9915ee92a85 100644
--- a/source/libsmb/namequery.c
+++ b/source/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;i<nmb2->answers->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;
}