2005-01-21 14:18:56 +03:00
/*
Unix SMB / CIFS implementation .
broadcast name resolution module
Copyright ( C ) Andrew Tridgell 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-21 14:18:56 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-21 14:18:56 +03:00
*/
# include "includes.h"
2006-03-07 14:07:23 +03:00
# include "libcli/resolve/resolve.h"
# include "system/network.h"
2006-08-17 17:37:04 +04:00
# include "lib/socket/netif.h"
2005-01-21 14:18:56 +03:00
/*
broadcast name resolution method - async send
*/
2006-11-09 04:11:45 +03:00
struct composite_context * resolve_name_bcast_send ( TALLOC_CTX * mem_ctx ,
struct event_context * event_ctx ,
struct nbt_name * name )
2005-01-21 14:18:56 +03:00
{
2005-01-21 16:13:24 +03:00
int num_interfaces = iface_count ( ) ;
const char * * address_list ;
2005-01-31 11:30:44 +03:00
struct composite_context * c ;
2006-02-15 07:18:11 +03:00
int i , count = 0 ;
2005-01-21 14:18:56 +03:00
2006-11-09 04:11:45 +03:00
address_list = talloc_array ( mem_ctx , const char * , num_interfaces + 1 ) ;
2005-01-21 16:13:24 +03:00
if ( address_list = = NULL ) return NULL ;
2005-01-21 14:18:56 +03:00
2005-01-21 16:13:24 +03:00
for ( i = 0 ; i < num_interfaces ; i + + ) {
2006-02-15 07:18:11 +03:00
const char * bcast = iface_n_bcast ( i ) ;
if ( bcast = = NULL ) continue ;
address_list [ count ] = talloc_strdup ( address_list , bcast ) ;
if ( address_list [ count ] = = NULL ) {
2005-01-21 16:13:24 +03:00
talloc_free ( address_list ) ;
return NULL ;
}
2006-02-15 07:18:11 +03:00
count + + ;
2005-01-21 14:18:56 +03:00
}
2006-02-15 07:18:11 +03:00
address_list [ count ] = NULL ;
2005-01-21 14:18:56 +03:00
2007-10-07 02:28:14 +04:00
c = resolve_name_nbtlist_send ( mem_ctx , event_ctx , name , address_list , true , false ) ;
2005-01-21 16:13:24 +03:00
talloc_free ( address_list ) ;
2005-01-21 14:18:56 +03:00
2005-01-21 16:13:24 +03:00
return c ;
2005-01-21 14:18:56 +03:00
}
/*
broadcast name resolution method - recv side
*/
2005-01-31 11:30:44 +03:00
NTSTATUS resolve_name_bcast_recv ( struct composite_context * c ,
2005-01-21 14:18:56 +03:00
TALLOC_CTX * mem_ctx , const char * * reply_addr )
{
2005-01-21 16:13:24 +03:00
return resolve_name_nbtlist_recv ( c , mem_ctx , reply_addr ) ;
2005-01-21 14:18:56 +03:00
}
/*
broadcast name resolution method - sync call
*/
NTSTATUS resolve_name_bcast ( struct nbt_name * name ,
TALLOC_CTX * mem_ctx ,
const char * * reply_addr )
{
2006-11-09 04:11:45 +03:00
struct composite_context * c = resolve_name_bcast_send ( mem_ctx , NULL , name ) ;
2005-01-21 14:18:56 +03:00
return resolve_name_bcast_recv ( c , mem_ctx , reply_addr ) ;
}