Exemplo n.º 1
0
status_t
BNetworkAddress::SetTo(const char* host, const char* service, uint32 flags)
{
	BReference<const BNetworkAddressResolver> resolver
		= BNetworkAddressResolver::Resolve(host, service, flags);
	if (resolver.Get() == NULL)
		return B_NO_MEMORY;
	status_t status = resolver->InitCheck();
	if (status != B_OK)
		return status;

	// Prefer IPv6 addresses

	uint32 cookie = 0;
	status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
	if (status != B_OK) {
		cookie = 0;
		status = resolver->GetNextAddress(&cookie, *this);
		if (status != B_OK)
			Unset();
	}
	fHostName = host;
	fStatus = status;
	return status;
}
Exemplo n.º 2
0
status_t
BNetworkAddress::SetTo(int family, const char* host, const char* service,
	uint32 flags)
{
	if (family == AF_LINK) {
		if (service != NULL)
			return B_BAD_VALUE;
		return _ParseLinkAddress(host);
			// SetToLinkAddress takes care of setting fStatus
	}

	BReference<const BNetworkAddressResolver> resolver
		= BNetworkAddressResolver::Resolve(family, host, service, flags);
	if (resolver.Get() == NULL)
		return B_NO_MEMORY;
	status_t status = resolver->InitCheck();
	if (status != B_OK)
		return status;

	uint32 cookie = 0;
	status = resolver->GetNextAddress(&cookie, *this);
	if (status != B_OK)
		Unset();
	fHostName = host;
	fStatus = status;
	return status;
}
Exemplo n.º 3
0
status_t
BNetworkAddress::SetTo(const char* host, uint16 port, uint32 flags)
{
	BReference<const BNetworkAddressResolver> resolver
		= BNetworkAddressResolver::Resolve(host, port, flags);
	if (resolver.Get() == NULL)
		return B_NO_MEMORY;
	status_t status = resolver->InitCheck();
	if (status != B_OK)
		return status;

	// Prefer IPv6 addresses

	uint32 cookie = 0;
	status = resolver->GetNextAddress(AF_INET6, &cookie, *this);
	if (status == B_OK)
		return B_OK;

	cookie = 0;
	return resolver->GetNextAddress(&cookie, *this);
}
Exemplo n.º 4
0
status_t
BNetworkAddress::SetTo(int family, const char* host, uint16 port, uint32 flags)
{
	if (family == AF_LINK) {
		if (port != 0)
			return B_BAD_VALUE;
		return _ParseLinkAddress(host);
	}

	BReference<const BNetworkAddressResolver> resolver
		= BNetworkAddressResolver::Resolve(family, host, port, flags);
	if (resolver.Get() == NULL)
		return B_NO_MEMORY;
	status_t status = resolver->InitCheck();
	if (status != B_OK)
		return status;

	uint32 cookie = 0;
	return resolver->GetNextAddress(&cookie, *this);
}