예제 #1
0
파일: nmblookup.c 프로젝트: javierag/samba
static bool query_one(const char *lookup, unsigned int lookup_type)
{
	int j, count;
	uint8_t flags;
	struct sockaddr_storage *ip_list=NULL;
	NTSTATUS status = NT_STATUS_NOT_FOUND;

	if (got_bcast) {
		char addr[INET6_ADDRSTRLEN];
		print_sockaddr(addr, sizeof(addr), &bcast_addr);
		d_printf("querying %s on %s\n", lookup, addr);
		status = name_query(lookup,lookup_type,use_bcast,
				    use_bcast?true:recursion_desired,
				    &bcast_addr, talloc_tos(),
				    &ip_list, &count, &flags);
	} else {
		status = name_resolve_bcast(
			lookup, lookup_type,
			talloc_tos(), &ip_list, &count);
	}

	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}

	if (give_flags) {
		d_printf("Flags: %s\n", query_flags(flags));
	}

	for (j=0;j<count;j++) {
		char addr[INET6_ADDRSTRLEN];
		if (translate_addresses) {
			char h_name[MAX_DNS_NAME_LENGTH];
			h_name[0] = '\0';
			if (sys_getnameinfo((const struct sockaddr *)&ip_list[j],
					sizeof(struct sockaddr_storage),
					h_name, sizeof(h_name),
					NULL, 0,
					NI_NAMEREQD)) {
				continue;
			}
			d_printf("%s, ", h_name);
		}
		print_sockaddr(addr, sizeof(addr), &ip_list[j]);
		d_printf("%s %s<%02x>\n", addr,lookup, lookup_type);
		/* We can only do find_status if the ip address returned
		   was valid - ie. name_query returned true.
		 */
		if (find_status) {
			if (!do_node_status(lookup, lookup_type, &ip_list[j])) {
				status = NT_STATUS_UNSUCCESSFUL;
			}
		}
	}

	TALLOC_FREE(ip_list);

	return NT_STATUS_IS_OK(status);
}
예제 #2
0
파일: cliconnect.c 프로젝트: jophxy/samba
struct cli_state *get_ipc_connect_master_ip_bcast(pstring workgroup, struct user_auth_info *user_info)
{
	//struct ip_service *ip_list;
	struct cli_state *cli;
	int i, count;
	struct in_addr *ip_list; 

	/* Go looking for workgroups by broadcasting on the local network */ 

	if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) {
		return False;
	}

	for (i = 0; i < count; i++) {
		cli = get_ipc_connect_master_ip(workgroup, user_info, &ip_list[i]);
		if (cli)
			return (cli);
	}
	return NULL;
}
예제 #3
0
파일: smbw.c 프로젝트: livebox/livebox2
/***************************************************** 
find a workgroup (any workgroup!) that has a master 
browser on the local network
*******************************************************/
static char *smbw_find_workgroup(void)
{
	fstring server;
	char *p;
	struct in_addr *ip_list = NULL;
	int count = 0;
	int i;

	/* first off see if an existing workgroup name exists */
	p = smbw_getshared("WORKGROUP");
	if (!p) p = lp_workgroup();
	
	slprintf(server, sizeof(server), "%s#1D", p);
	if (smbw_server(server, "IPC$")) return p;

	/* go looking for workgroups */
	if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) {
		DEBUG(1,("No workgroups found!"));
		return p;
	}

	for (i=0;i<count;i++) {
		static fstring name;
		if (name_status_find("*", 0, 0x1d, ip_list[i], name)) {
			slprintf(server, sizeof(server), "%s#1D", name);
			if (smbw_server(server, "IPC$")) {
				smbw_setshared("WORKGROUP", name);
				SAFE_FREE(ip_list);
				return name;
			}
		}
	}

	SAFE_FREE(ip_list);

	return p;
}