Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » TcpSocket::Connect now prefers IPv4 over IPv6
TcpSocket::Connect now prefers IPv4 over IPv6 [message #37596] Tue, 23 October 2012 15:18 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
After encountering the first site with IPv6 support, which did not go that well (I suspect network issues), I have for now changes Tcp::Connect to prefer IPv4 connection when available

bool TcpSocket::RawConnect(addrinfo *arp)
{
	if(!arp) {
		SetSockError("connect", -1, "not found");
		return false;
	}
	for(int pass = 0; pass < 2; pass++) {
		addrinfo *rp = arp;
		while(rp) {
			if(rp->ai_family == AF_INET == !pass && // Try to connect IPv4 in the first pass
			   Open(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) {
				if(connect(socket, rp->ai_addr, (int)rp->ai_addrlen) == 0 ||
				   GetErrorCode() == SOCKERR(EINPROGRESS) || GetErrorCode() == SOCKERR(EWOULDBLOCK)
				) {
					mode = CONNECT;
					return true;
				}
				Close();
			}
			rp = rp->ai_next;
		}
    }
	SetSockError("connect", -1, "failed");
	return false;
}

Re: TcpSocket::Connect now prefers IPv4 over IPv6 [message #37619 is a reply to message #37596] Sat, 27 October 2012 01:14 Go to previous messageGo to next message
DrinkWatah is currently offline  DrinkWatah
Messages: 12
Registered: October 2012
Location: Cali
Promising Member
Which header file did you use to resolve the TcpSocket reference? Was it <Web/Web.h>?
Re: TcpSocket::Connect now prefers IPv4 over IPv6 [message #37621 is a reply to message #37619] Sat, 27 October 2012 02:02 Go to previous message
omari is currently offline  omari
Messages: 265
Registered: March 2010
Experienced Member
to resolve TcpSocket :
<Core/Core.h>


omari.


regards
omari.
Previous Topic: WithSpin
Next Topic: FreeBSD port patch for release 12.10 (SVN 5485)
Goto Forum:
  


Current Time: Thu Apr 25 13:07:10 CEST 2024

Total time taken to generate the page: 0.01584 seconds