Skip to content

iOS app rejected, IPv6 not working #1526

@arg0d

Description

@arg0d

Hello,

I'm having trouble with Poco when trying to make HTTPS request from IPv6 only network.

My code is generic HTTPSClientSession + HTTPRequest.

When trying to connect using IPv6 IP address (the one with brackets), everything seems to work fine. Below is Google's IPv6 IP address that I used for testing.
[2a00:1450:400f:804::200e]

When trying to connect using hostname, Poco seems to choke.
ipv6.google.com

I have printed the IP addresses returned by DNS for ipv6.google.com and [2a00:1450:400f:804::200e] is the first one.

Changing code from Poco 1.7.6

void SocketAddress::init(const std::string& hostAddress, Poco::UInt16 portNumber)
{
	IPAddress ip;
	if (IPAddress::tryParse(hostAddress, ip))
	{
		init(ip, portNumber);
	}
	else
	{
		HostEntry he = DNS::hostByName(hostAddress);
		HostEntry::AddressList addresses = he.addresses();
		if (addresses.size() > 0)
		{
#if defined(POCO_HAVE_IPv6) && !defined(POCO_SOCKETADDRESS_DONT_PREFER_IPV4)
			// if we get both IPv4 and IPv6 addresses, prefer IPv4
			std::stable_sort(addresses.begin(), addresses.end(), AFLT());
#endif
			init(addresses[0], portNumber);
		}
		else throw HostNotFoundException("No address found for host", hostAddress);
	}
}


to

void SocketAddress::init(const std::string& hostAddress, Poco::UInt16 portNumber)
{
	IPAddress ip;
	if (IPAddress::tryParse(hostAddress, ip))
	{
		init(ip, portNumber);
	else
	}
	{
		HostEntry he = DNS::hostByName(hostAddress);
		HostEntry::AddressList addresses = he.addresses();
		if (addresses.size() > 0)
		{
			std::string host = addresses.at(0).toString();
			if (IPAddress::tryParse(host, ip)) {
				init(ip, portNumber);
			}
			else throw HostNotFoundException("No address found for host", hostAddress);
		}
		else throw HostNotFoundException("No address found for host", hostAddress);
	}
}

seems to solve the issue.

NOTE: The problem is not present on iOS simulator. Could it be a bug in DNS code which generates IPAddress objects, specific to iOS platform?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions